Top Ansible Interview Questions and Answers

Last updated on Feb 18 2022
Rahul Sharma

Table of Contents

Top Ansible Interview Questions and Answers

What is Ansible?

It is an open-source platform that facilitates configuration management, task automation, or application deployment. It is a valuable DevOps tool. It was written in Python and powered by Red Hat. It uses SSH to deploy SSH without incurring any downtime.

List Ansible’s advantages

Ansible has many strengths, including:

  • It’s agentless and only requires SSH service running on the target machines
  • Python is the only required dependency and, fortunately, most systems come with the language pre-installed
  • It requires minimal resources, so there’s low overhead
  • It’s easy to learn and understand since Ansible tasks are written in YAML.
  • Unlike other tools, most of which are Procedural, ansible is declarative; define the desired state, and Ansible fulfills the requirements needed to achieve it

Describe how Ansible works.

Ansible is broken down into two types of servers: controlling machines and nodes. Ansible is installed on the controlling computer, and the controlling machines manage the nodes via SSH.

The controlling machine contains an inventory file that holds the node system’s location. Ansible runs the playbook on the controlling machine to deploy the modules on the node systems. Since Ansible is agentless, there’s no need for a third-party tool to connect the nodes.

State the requirements for the Ansible server.

You need a virtual machine with Linux installed on it, running with Python version . or higher.

 

How do you set up Ansible?

You can use either the Python installer or a Linux-based installation process, such as apt or yum.

What is Ansible Tower?

It’s an enterprise-level web-based solution that increases Ansible’s accessibility to other IT teams by including an easy to use UI (user interface). Tower’s primary function is to serve as the hub for all of an organization’s automation tasks, allowing users to monitor configurations and conduct rapid deployments.

How do you test Ansible projects?

There are three testing methods available:

  1. Asserts

Asserts duplicates how the test runs in other languages like Python. It verifies that your system has reached the actual intended state, not just as a simulation that you’d find in check mode. Asserts shows that the task did the job it was supposed to do and changed the appropriate resources.

  1. Check Mode

Check mode shows you how everything would run if no simulation was done. Therefore, you can easily see if the project behaves the way you want it to. On the downside, check mode doesn’t run scripts and commands used in roles and playbooks. To get around this, you have to disable check mode for specific tasks by running “check_mode: no.”

  1. Manual Run

Just run the play and verify that the system is in its desired state. This testing choice is the easiest method, but it carries an increased risk because the results in a test environment may not be the same in a production environment.

How do you upgrade Ansible?

Upgrading Ansible is easy. Just use this command: sudo pip install ansible==<version-number>

What is “idempotency”?

idempotency is an important Ansible feature. It prevents unnecessary changes in the managed hosts. With idempotency, you can execute one or more tasks on a server as many times as you need to, but it won’t change anything that’s already been modified and is working correctly. To put it in basic terms, the only changes added are the ones needed and not already in place.

What is Ansible Galaxy?

This is a tool bundled with Ansible to create a base directory structure. Galaxy is a website that lets users find and share Ansible content. You can use this command to download roles from the website:

$ ansible-galaxy install username.role_name

What are CD and CI, and what is Ansible’s relationship with them?

CD stands for continuous delivery, and CI stands for continuous integration; both are software development practices.

In CD, developers build software that can be released into production at any given time. CI, on the other hand, consists of each developer uploading regularly scheduled integrations (usually daily), resulting in multiple integrations every day. Ansible is an ideal tool for CI/CD processes, providing a stable infrastructure for provisioning the target environment and then deploying the application to it.

What are roles in ansible ?

Answer: Roles are the advanced way to execute your playbooks on remote machines. Instead of writing one large playbook and making it very complicated, you can divide the playbook as per their section (Target, variables, tasks, handlers) by using roles and make the executing easier. By using roles, it becomes easier to manage very large playbooks. Roles will be present in “/etc/ansible” location. You can use “ansible galaxy” tool to create roles in ansible.

What is your understanding about Ansible ?

Answer: Ansible is a widely used IT configuration management tool . The best part of ansible is it is Open source so License is required and second one is it is Agent less , means we not need to Install any software on client machine to manage it .

What is Ansible Host and Node ?

Answer: Ansible has two part one is called Node machine and one is called Host Machine. The Node machine is here the ansible Server is installed and Host Machine is which is managed my Ansible Node.

How Ansible Communicate with its host Machine?

Answer: Ansible communicates with all its host machine using SSK key. We need to create an SSH Key using ssh-keygen command on Ansible Node machine and copy to all host machines.

Explain what a “playbook” is.

A playbook has a series of YAML-based files that send commands to remote computers via scripts. Developers can configure entire complex environments by passing a script to the required systems rather than using individual commands to configure computers from the command line remotely. Playbooks are one of Ansible’s strongest selling points and often referred to as the tool’s building blocks.

How do you use Ansible to create encrypted files?

To create an encrypted file, use the ‘ansible-vault create’ command.

$ ansible-vault create filename.yaml

You will get a prompt to create a password, and then to type it again for confirmation. You will now have access to a new file, where you can add and edit data.

What are “facts” in the context of Ansible?

Facts are newly discovered and known system variables, found in the playbooks, used mostly for implementing conditionals executions. Additionally, they gather ad-hoc system information.

You can get all the facts by using this command:

$ ansible all- m setup

 

What are tags?

When there’s an extensive playbook involved, sometimes it’s more expedient to run just a part of it as opposed to the entire thing. That’s what tags are for.

Speaking of tags, how do you filter out tasks?

You can filter out tasks in one of two ways:

  • Use –tags or –skip-tags options on the command line
  • If you’re in Ansible configuration settings, use the TAGS_RUN and TAGS_SKIP options.

What’s a handler?

In Ansible, a handler is similar to a regular task in a playbook, but it will only run if a task alerts the handler. Handlers are automatically loaded by roles/<role_name>/handlers/main.yaml. Handlers will run once, after all of the tasks are completed in a particular play.

Explain what an ask_pass module is.

It’s a playbook control module used to control a password prompt. It’s set to True by default.

What’s an ad hoc command?

Users initiate ad hoc commands to initiate actions on a host without using a playbook. Consider it a one-shot command.

Explain the difference between a playbook and a play.

A play is a set of tasks that run on one or more managed hosts. Plays consist of one or more tasks. A playbook consists of one or more plays.

What exactly is a configuration management tool?

Configuration management tools help keep a system running within the desired parameters. They help reduce deployment time and substantially reduce the effort required to perform repetitive tasks. Popular configuration management tools on the market today include Chef, Puppet, Salt, and of course, Ansible.

When do you use {{ }}?

One of Ansible’s most basic rules is: “Always use {{ }} except when:”

Explain how to access shell environment variables.

You can access the controlling machine’s existing variables by using the “env” lookup plugin. For instance, to access the value of the management machine’s home environment variable, you’d enter:

local_home:”{{lookup(‘env’,’HOME’)}}”

How do you keep data secret in a playbook?

If you want to keep secret data but still be able to share it publicly, then use Vault in playbooks. But if you’re using –v (verbose) mode and don’t want anyone to see the results, then use:

name: secret task

shell: /usr/bin/do_something –value={{ secret_value }}

no_log: True

What is CI/CD?

Continuous Integration is a software development practice where members of a team integrate their work frequently, usually, each person integrates at least daily leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.

Continuous Delivery is a process where you build software in such a way that it can be released to production at any time. Consider the diagram below:

a1 3

Let me explain the above diagram:

  • Automated build scripts will detect changes in Source Code Management (SCM) like Git.
  • Once the change is detected, source code would be deployed to a dedicated build server to make sure build is not failing and all test classes and integration tests are running fine.
  • Then, the build application is deployed on the test servers (pre-production servers) for User Acceptance Test (UAT).
  • Finally, the application is manually deployed on the production servers for release.

What is Configuration Management and how does it help an organization? 

Configuration Management is the practice of handling updates and changes systematically so that a system maintains its integrity over time. Configuration Management (CM) keeps a track of all the updates that are needed in a system and it ensures that the current design and build state of the system is up to date and functioning correctly.

Configuration Management can help an organization by overcoming the following challenges:

  • Finding out what changes need to be implemented when user requirements change.
  • Redoing and updating an implementation due to change in the requirements since the last implementation.
  • Reverting to an older version of the component because the latest version is flawed.
  • Replacing the wrong component because you couldn’t accurately determine which component needed replacing.

To better understand this consider the NYSE example:

The New York Stock Exchange (NYSE) encountered a glitch in their software which prevented them from trading stocks for approx minutes. On the night before, new software was installed on of its trading terminals. Unfortunately, the software failed to operate properly on the terminals.

Therefore, by using Configuration Management tools such as Ansible and Puppet, they reverted back to the old software. Had they not implemented CM, they would’ve taken a much longer time to fix the issue which would lead to a much bigger loss.

What is Ansible and what makes it stand out from the rest of the Configuration Management tools?

Ansible is an open source IT Configuration Management, Deployment & Orchestration tool. It aims to provide large productivity gains to a wide variety of automation challenges.

Here’s a list of features that makes Ansible such an effective Configuration Management and Automation tool:

  1. Simple: Uses a simple syntax written in YAML called playbooks.
  2. Agentless: No agents/software or additional firewall ports that you need to install on the client systems or hosts which you want to automate.
  3. Powerful and Flexible: Ansible’s capabilities allow you to orchestrate the entire application environment regardless of where it is deployed.
  4. Efficient: Ansible introduces modules as basic building blocks for your software. So, you can even customize it as per your needs.

How is Ansible different from Puppet?

a2 3

What are the different components of ansible? Explain Ansible architecture.

The below diagram depicts the Ansible architecture:

a3 4

The main component of Ansible is the Ansible automation engine. This engine directly interacts with various cloud services, Configuration Management Database (CMBD) and different users who write various playbooks to execute the Ansible Automation engine.

The Ansible Automation engine consists of the following components:

Inventories: These are a list of nodes containing their respective IP addresses, servers, databases, etc. which needs to be managed.

APIs: Just like any other API, the Ansible APIs are used for commuting various Cloud services, public or private services.

Modules: The modules are used to manage system resources, packages, libraries, files, etc. Ansible modules can be used to automate a wide range of tasks. Ansible provides around modules that automate nearly every part of your environment.

Plugins: If you want to execute Ansible tasks as a job, Ansible Plugins can be used. They simplify the execution of a task by building a job like an environment that basically contains pieces of code corresponding to some specific functionality. There are s of Plugins provided by Ansible. An example is the Action plugin, which acts as front ends to modules and can execute tasks on the controller before calling the modules themselves.

Networking: Ansible can also be used to automate different networks and services. It can do this by creating a playbook or an Ansible role that easily spans different network hardware.

Hosts: The Ansible Hosts/ Node systems are machines (Linux, Windows, etc) that are getting automated.

Playbooks: Playbooks are simple code files which describe the tasks that need to be executed. The Playbooks are written in YAML format. They can be used to automate tasks, declare configurations, etc.

CMDB: It is a database that acts as a storehouse for various IT installations. It holds data about various IT assets (also known as configuration items (CI)) and describes the relationships between such assets.

Cloud: It is a network of remote servers hosted on the Internet to store, manage, and process data, rather than a local server.

What are Ansible Server requirements?

If you are a windows user then you need to have a virtual machine in which Linux should be installed. It requires Python . version or higher. you fulfill these requirements and you’re good to go!

How would you install Ansible on a CentOS system?

This can be done in two simple steps:

Step : Set up EPEL Repository

EPEL (Extra Packages for Enterprise Linux) is an open source and free community-based repository project from Fedora team which provides high-quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux.

The Ansible package is not available in the default yum repositories, so we will enable EPEL repository by using the below command:

sudo rpm -ivh http://dl.fedoraproject.org/pub/epel//i/epel-release–.noarch.rpm

This will download all the necessary packages which will be required to install Ansible.

Step : Install Ansible

Now that your EPEL repository has been added, all you have to do now is install Ansible using the command below:

yum install ansible -y

That’s all! It’s a two-step process that barely takes a minute!

If you wish to check the version of Ansible installed on your system, use the command below:

ansible –version

Explain a few of the basic terminologies or concepts in Ansible.

Few of the basic terms that are commonly used while operating on Ansible are:

Controller Machine: The Controller machine is responsible for provisioning the servers that are being managed. It is the machine where Ansible is installed.

Inventory: An inventory is an initialization file that has details about the different servers you are managing.

Playbook: It is a code file written in the YAML format. A playbook basically contains the tasks that need to be executed or automated.

Task: Each task represents a single procedure that needs to be executed, e.g. Install a library.

Module: A module is a set of tasks that can be executed. Ansible has s of built-in modules, but you can also create custom ones.

Role: An Ansible role is a pre-defined way for organizing playbooks and other files in order to facilitate sharing and reusing portions of provisioning.

Play: A task executed from start to finish or the execution of a playbook is called a play.

Facts: Facts are global variables that store details about the system, like network interfaces or operating system.

Handlers: Are used to trigger the status of a service, such as restarting or stopping a service.

Explain the concept behind Infrastructure as Code (IaC).

Infrastructure as Code (IaC) is a process for managing and operating data servers, storage systems, system configurations, and network infrastructure.

In traditional configuration management practices, each minute configuration change required manual action by system administrators and the IT support team. But with IaC, all the configuration details are managed and stored in a standardized file system, wherein the system automatically manages infrastructure changes and deals with system configurations.

Therefore, we do not require most of the manual effort since everything is managed and automated by following the IaC approach. Tools such as Ansible can be used to implement IaC approach.

Compare Ansible with Chef. 

a4 2

What are Ad-hoc commands? Give an example.

Ad-hoc commands are simple one-line commands used to perform a certain task. You can think of Adhoc commands as an alternative to writing playbooks. An example of an Adhoc command is as follows:

ansible host -m netscaler -a “nsc_host=nsc.example.com user=apiuser password=apipass”

The above Adhoc command accesses the netscaler module to disable the server.

What are the variables in Ansible?

Variables in Ansible are very similar to variables in any programming language. Just like any other variable, an Ansible variable is assigned a value which is used in computing playbooks. You can also use conditions around the variables. Here’s an example:

 

 

 

– hosts: your hosts

vars:

port_Tomcat :

 

Here, we’ve defined a variable called port_Tomcat and assigned the port number to it. Such a variable can be used in the Ansible Playbook.

What is the difference between a variable name and an environment variable?

a5 2

What are the Ansible Modules? Explain the different types. 

Ansible modules are a small set of programs that perform a specific task. Modules can be used to automate a wide range of tasks. Modules in Ansible are considered to be idempotent or in other words, making multiple identical requests has the same effect as making a single request.

There are types of modules in Ansible:

  1. Core modules
  2. Extras modules

Core Modules

These are modules that the core Ansible team maintains and will always ship with Ansible itself. They will also receive a slightly higher priority for all requests than those in the “extras” repos. The source of these modules is hosted by Ansible on GitHub in the Ansible-modules-core.

Extras Modules

These modules are currently shipped with Ansible but might be shipped separately in the future. They are also mostly maintained by the Ansible Community. Non-core modules are still fully usable but may receive slightly lower response rates for issues and pull requests.

Popular “extras” modules may be promoted to core modules over time. The source for these modules is hosted by Ansible on GitHub in the Ansible-modules-extras.

What is Ansible Task? 

Ansible Tasks allow you to break up bits of configuration policy into smaller files. These are blocks of code that can be used to automate any process. For example, if you wish to install a package or update a software, you can follow the below code snippet:

Install <package_name>, update <software_name>

Can you explain what are playbooks in Ansible? Explain with some examples.

Playbooks in Ansible are written in the YAML format. It is a human-readable data serialization language. It is commonly used for configuration files. It can also be used in many applications where data is being stored.

For Ansible, nearly every YAML file starts with a list. Each item in the list is a list of key/value pairs, commonly called a “hash” or a “dictionary”. So, we need to know how to write lists and dictionaries in YAML.

All members of a list are lines beginning at the same indentation level starting with a “- ” (dash and space). More complicated data structures are possible, such as lists of dictionaries or mixed dictionaries whose values are lists or a mix of both.

For example, if you want a playbook containing details about the USA:

 

 

 

 

-USA

-continent: North America

-capital: Washington DC<a name=”AnsibleIntermediateLevelInterviewQuestions”></a>

-population: million

Can you write a simple playbook to install Nginx on a host machine?

Step : Generate a public SSH key and by using SSH connect to your host.

Follow the command below:

$ ssh-keygen

As shown above, a public SSH key is generated.

Step : Next, copy the public SSH key on your hosts. Follow the below command to do it:

ssh-copy-id -i root@IP address of your host

Step : List the IP addresses of your hosts/nodes in your inventory.

Follow the below command:

vi /etc/ansible/hosts

Once you run the command, the vi editor will open where you can list down the IP addresses of your hosts. This is now your inventory.

Step : To check if the connection has been established, let’s ping:

The above image shows that a connection has been made between the control machine and the host.

Step : Create a playbook to install Nginx on the host machine.  To create a playbook you just need to open a file with a yml extension, like shown below:

vi <Name of your file>.yml

In an Ansible Playbook, the tasks are defined as a list of dictionaries and are executed from top to bottom.

Each task is defined as a dictionary that can have several keys, such as “name” or “sudo” which signify the name of the task and whether it requires sudo privileges.

A variable server_port is set that listens on TCP port  for incoming requests.

Here, the first task is to get the necessary package for installation of Nginx and then install it. Internally, Ansible will check if the directory exists and create it if it’s not, otherwise, it will do nothing.

The next task is to configure Nginx. In Nginx, contexts contain configuration details.

Here, the template is a file you can deploy on hosts. However, template files also include some reference variables which are pulled from variables defined as part of an Ansible playbook or facts gathered from the hosts. Facts containing the configuration details are being pulled from a source directory and being copied to a destination directory.

Handlers here define the action to be performed only upon notification of tasks or state changes. In this playbook, we defined, notify: restart Nginx handler which will restart Nginx once the files and templates are copied to hosts.

Now, save the file and exit.

Step : Run the playbook, using the command below:

ansible-playbook <name of your file>.yml

Step : Check if Nginx is installed on the machine. Use the following command:

ps waux | grep nginx

In the above image, the different process IDs  and  are running which shows that Nginx is running on your host machines.

How would you access a variable of the first host in a group?

This can be done by executing the below command:

{{ hostvars[groups[‘webservers’][]][‘ansible_eth’][‘ipv’][‘address’] }}

In the above command, we’re basically accessing the hostname of the first machine in the webservers group. If you’re using a template to do this, use the Jinja ‘#set’ or you can also use set_fact, like shown below:

 

 

– set_fact: headnode={{ groups[[‘webservers’][]] }}

– debug: msg={{ hostvars[headnode].ansible_eth.ipv.address }}

 

Why is ‘{{ }}’ notation used? And how can one interpolate variables or dynamic variable names? 

One basic rule is to ‘always use {{}} except when:’. Conditionals are always run through Jinja as to resolve the expression. Therefore, ‘when:failed_when:’ and ‘changed_when:’ are always templated and we should avoid adding {{}}.
In other cases, except when clause, we have to use brackets, otherwise, differentiating between an undefined variable and a string will be difficult to do.

What is Ansible role and how are they different from the playbook? 

Ansible Roles is basically another level of abstraction used to organize playbooks. They provide a skeleton for an independent and reusable collection of variables, tasks, templates, files, and modules which can be automatically loaded into the playbook. Playbooks are a collection of roles. Every role has specific functionality.

Let’s understand the difference between Ansible roles and playbook with an example.

Suppose you want your playbook to perform different tasks on different systems, would you use a single playbook for this? No, using a single playbook can make it confusing and prone to blunders. Instead, you can create different roles, where each role will perform one task. Then, all you need to do is, mention the name of the role inside the playbook to call them.

How do I write an Ansible handler with multiple tasks?

Suppose you want to create a handler that restarts a service only if it is already running.

Handlers can “listen” to generic topics, and tasks can notify those topics as shown below. This functionality makes it much easier to trigger multiple handlers. It also decouples handlers from their names, making it easier to share handlers among playbooks and roles:

 

 

 

 

 

 

 

 

 

 

 

– name: Check if restarted

shell: check_is_started.sh

register: result

listen: Restart processes

 

 

 

– name: Restart conditionally step

service: name=service state=restarted

when: result

listen: Restart processes

 

How to keep secret data in a playbook? 

Suppose you have a task that you don’t want to show the output or command given to it when using -v (verbose) mode, the following task can be used to do it:

 

 

 

– name: secret task

shell: /usr/bin/do_something –value={{ secret_value }}

no_log: True

This can be used to keep verbose output but hide sensitive information from others who would otherwise like to be able to see the output.

The no_log attribute can also apply to an entire play:

 

 

– hosts: all

no_log: True

 

What are Ansible Vaults and why are they used? 

Ansible Vault is a feature that allows you to keep all your secrets safe. It can encrypt entire files, entire YAML playbooks or even a few variables. It provides a facility where you can not only encrypt sensitive data but also integrate them into your playbooks.

Vault is implemented with file-level granularity where the files are either entirely encrypted or entirely unencrypted. It uses the same password for encrypting as well as for decrypting files which makes using Ansible Vault very user-friendly.

How to create encrypted files using Ansible?

To create an encrypted file, use the ‘ansible-vault create’ command and pass the filename.

$ ansible-vault create filename.yaml

You’ll be prompted to create a password and then confirm it by re-typing it.

Once your password is confirmed, a new file will be created and will open an editing window. By default, the editor for Ansible Vault is vi. You can add data, save and exit.

This is your encrypted file:

What is Ansible Tower?

Ansible Tower is Ansible at a more enterprise level. It is a web-based solution for managing your organization with a very easy user interface that provides a dashboard with all of the state summaries of all the hosts, allows quick deployments, and monitors all configurations.

The tower allows you to share the SSH credentials without exposing them, logs all the jobs, manage inventories graphically and syncs them with a wide variety of cloud providers.

What features does the Ansible Tower provide? 

  • Ansible Tower Dashboard – The Ansible Tower dashboard displays everything going on in your Ansible environment like the hosts, inventory status, the recent job activity and so on.
  • Real-Time Job Updates – As Ansible can automate the complete infrastructure, you can see real-time job updates, like plays and tasks broken down by each machine either been successful or a failure. So, with this, you can see the status of your automation, and know what’s next in the queue.
  • Multi-Playbook Workflows – This feature allows you to chain any number of playbooks, regardless of the usage of different inventories, utilizes various credentials, or runs different users.
  • Who Ran What Job When – As the name suggests, you can easily know who ran what job where and when as, all the automation activity is securely logged in Ansible Tower.
  • Scale Capacity With Clusters – We can connect multiple Ansible Tower nodes into an Ansible Tower cluster as the clusters add redundancy and capacity, which allow you to scale Ansible automation across the enterprise.
  • Integrated Notifications – This feature lets you notify a person or team when a job succeeds or fails across the entire organization at once, or customize on a per-job basis.
  • Schedule Ansible Jobs – Different kinds of jobs such as Playbook runs, cloud inventory updates, and source control updates can be scheduled inside Ansible Tower to run according to the need.
  • Manage & Track Inventory – Ansible Tower helps you manage your entire infrastructure by letting you easily pull inventory from public cloud providers such as Amazon Web Services, Microsoft Azure, and more.
  • Self-Service – This feature of Ansible Tower lets you launch Playbooks with just a single click. It can also, let you choose from available secure credentials or prompt you for variables and monitor the resulting deployments.
  • REST API & Tower CLI Tool – Every feature present in Ansible Tower is available via Ansible Tower’s REST API, which provides the ideal API for a systems management infrastructure. The Ansible Tower’s CLI tool is available for launching jobs from CI systems such as Jenkins, or when you need to integrate with other command-line tools.
  • Remote Command Execution – You can run simple tasks such as add users, restart any malfunctioning service, reset passwords on any host or group of hosts in the inventory with Ansible Tower’s remote command execution.

How is Ansible used in a Continuous Delivery pipeline? Explain.

It is well known that in DevOps development and operations work is integrated. This integration is very important for modern test-driven applications. Hence, Ansible integrates this by providing a stable environment to both development and operations resulting in a smooth delivery pipeline.

When developers begin to think of infrastructure as part of their application i.e as Infrastructure as code (IaC), stability and performance become normative. Infrastructure as Code is the process of managing and provisioning computing infrastructure and their configuration through machine-processable definition files, rather than physical hardware configuration or the use of interactive configuration tools. This is where Ansible automation plays a major role and stands out among its peers.

In a Continuous Delivery pipeline, Sysadmins work tightly with developers, development velocity is improved, and more time is spent doing activities like performance tuning, experimenting, and getting things done, and less time is spent fixing problems.

 

How can looping be done over a list of hosts in a group, inside of a template?

An easy way to do this is to iterate over a list of hosts inside of a host group, in order to fill a template configuration file with a list of servers. This can be done by accessing the “$groups” dictionary in your template, like so:

 

 

 

{% for host in groups[‘db_servers’] %}

{{ host }}

{% endfor %}

In order to access facts about these hosts, like, the IP address of each hostname, you need to make sure that the facts have been populated. For instance, make sure you have a play that talks to db_servers:

 

 

 

– hosts: db_servers

tasks:

– debug: msg=”doesn’t matter what you do, just that they were talked to previously.”

Now you can use the facts within your template, like so:

 

 

 

{% for host in groups[‘db_servers’] %}

{{ hostvars[host][‘ansible_eth’][‘ipv’][‘address’] }}

{% endfor %}

How can I display all the inventory vars defined for my host?

In order to check the inventory vars resulting from what you’ve defined in the inventory, you can execute the below command:

ansible -m debug -a “var=hostvars[‘hostname’]” localhost

This will list down all the inventory vars.

How should one configure a jump host to access servers that I have no direct access to?

The first step would be to set a ProxyCommand in the ansible_ssh_common_args inventory variable. All arguments that are defined in this variable are added to the sftp/scp/ssh command line when connecting to the relevant host. Let’s look at an example, consider the below inventory group:

 

 

 

[gatewayed]

foo ansible_host=…

bar ansible_host=…

Next, you can create group_vars/gatewayed.yml containing the following:

ansible_ssh_common_args: ‘-o ProxyCommand=”ssh -W %h:%p -q user@gateway.example.com”‘

Ansible will then append these arguments to the command line while trying to connect to any hosts in the group gatewayed.

How can you handle different machines needing different user accounts or ports to log in with?

The simplest way to do this is by setting inventory variables in the inventory file.

Let’s consider that these hosts have different usernames and ports:

 

 

 

[webservers]

asdf.example.com ansible_port= ansible_user=alice

jkl.example.com ansible_port= ansible_user=bob

Also, if you wish to, you can specify the connection type to be used:

 

 

 

 

[testcluster]

localhost ansible_connection=local

/path/to/chroot ansible_connection=chroot

foo.example.com ansible_connection=paramiko

To make this more clear it is best to keep these in group variables or file them in a group_vars/<group-name> file.

Is it unsafe to bulk-set task arguments from a variable?

To set all the arguments in a task you can use the dictionary-typed variable. Even though this is usually good for dynamic executions, it induces a security risk. Therefore, when this happens, Ansible issues a warning. For example, consider the below code:

 

 

 

 

 

 

vars:

usermod_args:

name: testuser

state: present

tasks:

– user: ‘{{ usermod_args }}’

This example is safe but creating similar tasks is risky because the parameters and values passed to usermod_args could be overwritten by malicious values in the host facts on a compromised target machine.

How can you create a LAMP stack and deploy a webpage by using Ansible?

Suppose you’re trying to deploy a website on systems, every website deployment will require a base OS, web-server, Database, and PHP. We use ansible playbook to install these prerequisites on all systems at once.

For this particular problem statement, you can use two virtual machines, one as a server where Ansible is installed and the other machine acts as the remote host. Also, I’ve created a simple static webpage saved in a folder index which has two files, index.html, and style.css.

In the below code I’ve created a single Ansible playbook to install Apache, MySql, and PHP:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

# Setup LAMP Stack

–  hosts: host

tasks:

 

–  name: Add ppa repository

become: yes

apt_repository: repo=ppa:ondrej/php

 

–  name: Install lamp stack

become: yes

apt:

pkg:

– apache

– mysql-server

– php.

– php.-mysql

state: present

update cache: yes

 

–  name: start apache server

become: yes

service:

name: apache

state: started

enabled: yes

 

–  name: start mysql service

become: yes

services:

name: mysql

state: started

enabled: yes

 

–  name:  create target directory

file: path=/var/www/html state=directory mode=

 

– name:  deploy index.html

became: yes

copy:

src: /etc/ansible/index/index.html

dest: var/www/html/index/index.html

Now, there are main tasks, each task performs a specific function:

  • The first task adds the repository required to install MySQL and PHP.
  • The second task installs apache, MySQL-server, PHP, and PHP-MySQL.
  • The third and fourth task starts the Apache and MySQL service.
  • The fifth task creates a target directory in the host machine and
  • Finally, the sixth task executes the index.html file, it picks up the file from the server machine and copies it into the host machine.

To finally run this playbook you can use the following command:

$ ansible-playbook lamp.yml -K

How do I set the PATH or any other environment variable for a task?

The environment variables can be set by using the ‘environment’ keyword. It can be set for either a task or an entire playbook as well. Follow the below code snippet to see how:

 

 

 

environment:

PATH: “{{ ansible_env.PATH }}:/thingy/bin”

SOME: value

 

How can one generate encrypted passwords for the user module?

There are a couple of ways to do this. The simplest way is to use the ad-hoc command:

ansible all -i localhost, -m debug -a “msg={{ ‘mypassword’ | password_hash(‘sha’, ‘mysecretsalt’) }}”

Another way is to use the mkpasswd functionality available on Linux systems:

mkpasswd –method=sha-

However, if you’re using a macOS then you can generate these passwords using Python. To do this you must first install the Passlib password hashing library:

pip install passlib

After installing it, the SHA password values can be generated in the following manner:

python -c “from passlib.hash import sha_crypt; import getpass; print(sha_crypt.using(rounds=).hash(getpass.getpass()))”

Suppose you’re using Ansible to configure the production environment and your playbook uses an encrypted file. Encrypted files prompt the user to enter passwords. But since Ansible is used for automation, can this process be automated?

Yes, Ansible uses a feature called password file, where all the passwords to your encrypted files can be saved. So each time the user is asked for the password, he can simply make a call to the password file. The password is automatically read and entered by Ansible.

$ ansible-playbook launch.yml –vault-password-file ~/ .vault_pass.txt

Having a separate script that specifies the passwords is also possible. You need to make sure the script file is executable and the password is printed to standard output for it to work without annoying errors.

$ ansible-playbook launch.yml –vault-password-file ~/ .vault_pass.py

Have you worked with Ansible before? Please share your experience.

Be very honest here. If you have used ansible before then talk about your experience. Talk about the projects that required ansible. You can tell the interviewer about how Ansible has helped you in provisioning and configuration management. If you haven’t used Ansible before then just talk about any related tools that you’ve used. These related tools could be anything like Git, Jenkins, Puppet, Chef, Satltstack, etc.

Be very honest because they know if you’re lying.

Is Ansible an Open Source tool?

Yes, Ansible is open source. That means you take the modules and rewrite them. Ansible is an open-source automated engine that lets you automate apps.

How can you connect other devices within Ansible?

Once Ansible is installed on the controlling machines, an inventory file is created. This inventory file specifies the connection between other nodes. A connection can be made using a simple SSH. To check the connection to a different device, you can use the ping module.

ansible -m ping all

The above command checks the connection to all the nodes specified in the inventory file.

Is it possible to build our modules in Ansible?

Yes, we can create our own modules within Ansible. It’s an open-source tool which basically works on python. You can start creating your own modules. The only requirements would be to be amazingly good at programming.

What does Fact mean in Ansible?

When any new variable about the system has been discovered it’s considered to be a “fact” in the playbook. Facts are mainly used to implement conditional executions. It can also be used to get the ad-hoc information about the system.

You can get facts with the following command:

$ ansible all- m setup

So, when you want to extract only a part of the information, you use the setup module to filter out only the needed information.

What is the ask_pass module in Ansible?

Ask_pass is the control module in an Ansible playbook. This controls the prompting of the password when the playbook is getting executed. By default, it’s always set to True. If you are using SSH keys for authentication purposes then you really don’t have to change this setting at all.

Explain the callback plugin in Ansible?

Callback plugins are enable adding new behaviors to Ansible when responding to events. By default, callback plugins control most of the output you see when running the command line program. It can also be used to add additional output, integrate with other tools, etc.

Does Ansible support AWS?

Ansible has hundreds of modules supporting AWS and some of them include:

  • Autoscaling groups
  • CloudFormation
  • CloudTrail
  • CloudWatch
  • DynamoDB
  • ElastiCache
  • Elastic Cloud Compute (EC)
  • Identity Access Manager (IAM)
  • Lambda
  • Relational Database Service (RDS)
  • Route
  • Security Groups
  • Simple Storage Service (S)
  • Virtual Private Cloud (VPC)

Does Ansible support hardware provisioning?

Yes, Ansible can provision hardware. A lot of companies are still stuck on to massive data centers of hardware. There are a few requirements. You must set up some services before you go ahead. Some of them are – DHCP, PXE, TFTP, Operating System Media, Web Server, etc.

Write an Ansible playbook to automate the starting of EC instance.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

– name: Create an ec instance

hosts: web

gather_facts: false

 

vars:

region: us-east-

instance_type: t.micro

ami: ami-eaec

keypair: priyajdm

 

tasks:

 

– name: Create an ec instance

ec:

aws_access_key: ‘********************’

aws_secret_key: ‘****************************************’

key_name: “{{ keypair }}”

group: launch-wizard-

instance_type: “{{ instance_type }}”

image: “{{ ami }}”

wait: true

region: “{{ region }}”

count:

vpc_subnet_id: subnet-fefdc

assign_public_ip: yes

register: ec

  • We start by mentioning AWS access key id and secret key using the parameters aws_access_key and aws-secret_key.
  • key_name: pass the variable that defines the keypair being used here
  • group: mention the name of the security group. This defines the security rules of the EC instance we’re trying to bring up
  • instance_type: pass the variable that defines the type of instance we’re using here
  • image: pass the variable that defines the AMI of the image we’re trying to start.
  • wait: This has a boolean value of either true or false. If true, it waits for the instance to reach the desired state before returning
  • region: pass the variable that defines the region in which an EC instance needs to be created.
  • count: This parameter specifies the number of instances that need to be created. In this case, I’ve only mentioned only one but this depends on your requirements.
  • vpc_subnet_id: pass the subnet id in which you wish to create the instance
  • assign_public_ip: This parameter has a boolean value. If true like in our case, a public IP will be assigned to the instance when provisioned within VPC.

Can you copy files recursively onto a target host? If yes, how?

Yes, you can copy files recursively onto a target host using the copy module. It has a recursive parameter which copies files from a directory. There is another module called synchronize which is specifically made for this.

 

 

 

 

– synchronize:

src: /first/absolute/path

dest: /second/absolute/path

delegate_to: “{{ inventory_hostname }}”

Write a playbook to create a backup of a file in the remote servers before copy.

This is pretty simple. You can use the below playbook:

 

 

 

 

 

 

 

– hosts: blocks

tasks:

– name: ansible copy file backup example

copy:

src: ~/helloworld.txt

dest: /tmp

backup: yes

 

What is Ansible?

Ansible is developed in Python language. It is a software tool. It is useful while deploying any application using ssh without any downtime. Using this tool one can manage and configure software applications very easily.

 

Ansible Playbooks vs Roles

a6 2


What are the advantages of using Ansible?

The main three advantages of using this tool is,i.e. Ansible

  • Agentless
  • Very low overhead
  • Good performance

Compare Ansible VS Puppet

a7 2

How Ansible Works?

There are many similar automation tools available like Puppet, Capistrano, Chef, Salt, Space Walk etc, but Ansible categorize into two types of server: controlling machines and nodes.

The controlling machine, where Ansible is installed and Nodes are managed by this controlling machine over SSH. The location of nodes are specified by controlling machine through its inventory.

The controlling machine (Ansible) deploys modules to nodes using SSH protocol and these modules are stored temporarily on remote nodes and communicate with the Ansible machine through a JSON connection over the standard output.

Ansible is agent-less, that means no need of any agent installation on remote nodes, so it means there are no any background daemons or programs are executing for Ansible, when it’s not managing any nodes.

Ansible can handle ’s of nodes from a single system over SSH connection and the entire operation can be handled and executed by one single command ‘ansible’. But, in some cases, where you required to execute multiple commands for a deployment, here we can build playbooks.
Playbooks are bunch of commands which can perform multiple tasks and each playbooks are in YAML file format.

What’s the Use of Ansible.

Ansible can be used in IT Infrastructure to manage and deploy software applications to remote nodes. For example, let’s say you need to deploy a single software or multiple software to ’s of nodes by a single command, here ansible comes into picture, with the help of Ansible you can deploy as many as applications to many nodes with one single command, but you must have a little programming knowledge for understanding the ansible scripts.

We’ve compiled a series on Ansible, title ‘Preparation for the Deployment of your IT Infrastructure with Ansible IT Automation Tool‘, through parts – and covers the following topics.

Explain Ansible architecture?

Ansible automation engine is the main component of Ansible, that interacts directly with the configuration management database, cloud services and various users who write playbooks to execute it.

The below figure depicts the Ansible architecture:

a8 2

The following are the components of the Ansible Automation engine:

  • Modules: Ansible works effectively by connecting nodes and pushing out scripts called “Ansible modules”. It helps to manage packages, system resources, files, libraries, etc.
  • Inventories: These are the lists of nodes or hosts containing their databases, servers, IP addresses, etc.
  • APIs: These used for commuting public or private cloud services.
  • Plugins: Plugins augment Ansible’s core functionality. Also offers extensions and options for the core features of Ansible – transforming data, connecting to inventory, logging output, and more.
  • Playbooks: Describes the tasks that need to be executed. They are simple code files written in YAML format and can be used to declare configurations, automating tasks, etc.
  • Hosts: Hosts are node systems which are automated by Ansible on any machines like Linux, RedHat, Windows, etc.
  • Networking: Ansible can be used to automate multiple networks and services. It uses a secure and simple automation framework for IT operations and development.
  • Cloud: A system of remote servers that allows you to store, manage, and process data, rather than a local server.
  • CMDB: It is a type of repository which acts as a data warehouse for the IT installations.

 

What is CI/CD? And how Ansible is related to it?

  • CI/CD is one of the best software development practices to implement and develop code effectively. CI stands for Continuous Integration, and CD stands for continuous delivery.
  • Continuous Integration is a collection of practices that drive developers to implement and check-in code to version control repositories.
  • Continuous delivery picks up where continuous Integration ends. This process builds software in such a way that software will be released into production at any given time.
  • Ansible is an excellent tool for CI/CD processes, which provide a stable infrastructure to a provision target environment and then deploy the application to it.

Can you create reusable content with Ansible?

Yes, Ansible has the concept of roles that helps to create reusable content. To create a role, you need to follow Ansible’s conventions of structuring directories and naming files.

 Is Ansible a Configuration management tool?

Configuration management is the practice to handle updates and manage consistency of a product’s performance over a particular period of time. Ansible is an open-source IT Configuration Management tool, which automates a wide variety of challenges in complex multi-tier IT application environments.

 

Why are you attracted to science and science fiction?

Early imprinting, maybe, for the science fiction. When I was quite small a family friend let me read his s run of ‘Galaxy’ magazine. My favourite aunt pressed John Wyndham’s ‘The Day of the Triffids’ on me; a more terrifying great-aunt gave me G.K. Chesterton’s fantastic novels; and so on.
The incurable addiction had begun. Meanwhile, science classes just seemed to be the part of school that made most sense, and I fell in love with Pelican pop-maths titles – especially Kasner’s and Newman’s ‘Mathematics and the Imagination’ and all those books of Martin Gardner’s ‘Scientific American’ columns.

Tell us about your software company and what sort of software it produced(s).

This goes back to the s and the Apricot home computers, the early, pretty and non-PC-compatible ones. My pal Chris Priest and I both used them for word processing, and he persuaded me to put together a disk of utilities to improve the bundled ‘SuperWriter’ w/p, mostly written in Borland Turbo Pascal and later : two-column printing, automated book index preparation, cleaning the crap out of the spellcheck dictionary, patching SuperWriter to produce dates in UK format, and so on.

Then I redid the index software (‘AnsibleIndex’) in CP/M for the Amstrad PCW and its Locoscript word processors. When the Apricot market collapsed, I wrote an Apricot emulator in assembler so that people could keep using their horrible but familiar old software on a PC. Eventually, in a fit of nostalgia, I collected all my columns for ‘Apricot File’ and various Amstrad PCW magazines as books unoriginally titled ‘The Apricot Files’ and ‘The Limbo Files’. (That’s probably enough self-promotion, but there’s lots more at https://ansible.uk/.)

Describe your newsletter Ansible and who it’s aimed at.

It appears monthly and has been called the ‘Private Eye’ of science fiction, but isn’t as cruel and doesn’t (I hope) recycle old jokes quite as relentlessly. Though I feel a certain duty to list some bread-and-butter material like conventions, award winners and deaths in the field, ‘Ansible’ skips the most boring SF news – the long lists of books acquired, books published, book sales figures, major new remainders – in favour of quirkier items and poking fun at SF notables. The most popular departments quote terrible lines from published SF/fantasy and bizarre things said about SF by outsiders (‘As Others See Us’). All the back issues of ‘Ansible’ since it started in can be read online.

So how does Ansible work? Please explain in detail?

Within the market, they are many automation tools like Puppet, Capistrano, Chef, Salt, Space Walk etc.

  • When it comes to Ansible, this tool is categorized into two types of servers:
    . Controlling machines
    . Nodes
  • Ansible is an agentless tool so it doesn’t require any mandatory installations on remote nodes. So there is no background programs that are executed while it is managing any nodes.
  • Ansible is able to handle a lot of nodes from a single system over SSH connection.
  • Playbooks are defined as a bunch of commands where they are capable of performing multiple tasks and they are in YAML file format.

What does Ansible offer?

  • Security and Compliance policy integration
  • Automated workflow for Continuous Delivery
  • Simplified orchestration
  • App deployment
  • Configuration management
  • Streamlined provisioning

Can we manage Windows Nano Server using Ansible?

No, it is not possible to manage Windows Nano Server using Ansible as it doesn’t have the full access to the .Net framework, which is primarily used by internal components and modules.

How to create an empty file with Ansible?

To create an empty file, Ansible uses a file module. For this, we need to set up two parameters.

  • Path – This place represents the location where the file gets created, either the relative or an absolute path. Also, the name of the file includes here.
  • State – For creating a new file, this parameter should be set to touch.

How will you set the environment variable or any path for a task or entire playbook?

To set the environment variables, we use the environment keyword. We’ll use it at the task or other levels in the play:

 

 

 

environment:

PATH: “{{ ansible_env.PATH }}:/thingy/bin”

SOME: value

How would you describe yourself in terms of what you do and how you’d like to be remembered?

Obviously I’d like to be remembered as a master of prose who forever changed the face of literature as we know it, but I’m going to have to settle for being remembered as a science fiction writer (and, more and more, critic) who wrote the occasional funny line and picked up a few awards.

Do we have any Web Interface/ Rest API etc for this?

Yes, Ansible Inc makes a great efficient tool. It is easy to use.

What is Ansible Tower?

Ansible is classified as a web-based solution which makes Ansible very easy to use. It is considered to be or acts like a hub for all of your automation tasks. The tower is free for usage till nodes.

What are the features of Ansible Tower?

  • Ansible Dashboard
  • Real-time job status updates
  • Multi-playbook workflows
  • Who Ran What Job When
  • Scale capacity with tower clusters
  • Integrated notifications
  • Schedule ansible jobs
  • Manage and track inventory
  • Remote command execution
  • REST API & Tower CLI Tool

How do change the documentation and submit it?

Usually, the documentation is kept in the main project folder in the git repository. For complete instructions on this can be available in docs.

How do you access Shell Environment Variables?

If you are just looking to access the existing variables then you can use “env” lookup plugin.
For example:
Accessing the value of Home environment variable on management machine:

local_home:”{{lookup(‘env’,’HOME’)}}”

How can you speed up management inside in EC?

It is not advised to manage a group of EC machines from your laptop.
The best way is to connect to a management node inside Ec first and then execute Ansible from there.

Is it possible to increase the Ansible reboot module to more than seconds?

Yes, it is possible to increase the Ansible reboot module to specific values using the below syntax:

 

 

 

 

 

– name: Reboot a Linux system

 

reboot:

 

reboot_timeout:

 

 

Explain how you can generate encrypted passwords for the user module?

Ansible ad-hoc command is the easiest option:

ansible all -i localhost, -m debug -a “msg={{ ‘mypassword’ | password_hash(‘sha’, ‘mysecret’) }}”

The mkpasswd utility available on the Linux systems is also a best option:

mkpasswd –method=sha-

Can you keep data secret in the playbook?

Yes. If any task that you want to keep secret in the playbook when using -v (verbose) mode, the following playbook attribute will be helpful:

 

 

 

– name: secret task

shell: /usr/bin/do_something –value={{ secret_value }}

no_log: True

It hides sensitive information from others and provides the verbose output.

What is idempotency?

Idempotence is an essential feature of Ansible, which helps you to execute one or more tasks on a server as many times needed, but without changing the result beyond the initial application.

 Can you create encrypted files with Ansible?

Yes, using ‘ansible-vault create’ command, we can create encrypted files

$ ansible-vault create filename.yaml

What is the difference between a playbook and a play?

A playbook is a list of plays. A play is a set of tasks and roles that run on one or more managed hosts. Play includes one or more tasks.

How will you get access to the ansible host when I delegate a task?

We can access it through host variables and even works for all the overridden variables like ansible_port, ansible_user, etc.

original_host: “{{ hostvars[inventory_hostname][‘ansible_host’] }}”

Explain the Ansible Tag’s usage?

A tag is an attribute that sets the ansible structure(plays, tasks, roles). When there’s an extensive playbook needed, it’s more useful to run just a part of it as opposed to the entire thing. That’s where tags usage is required.

What are handlers?

In Ansible, handlers are just like normal tasks in a playbook but run when tasks include the notify directive and also indicate that it changed something. It runs only once after all the tasks executed in a particular play. It automatically loads through roles//handlers/main.yaml.

They are used to trigger the status of a service, such as restarting or stopping a service.

How will you upgrade Ansible?

Using the command “sudo pip install ansible==”, we can easily upgrade Ansible.

How can you use docker modules in Ansible?

Docker modules require docker-py installed on the host running Ansible.

$ pip install ‘docker-py>=..’

The docker_service module also requires docker-compose

$ pip install ‘docker-compose>=..’

Explain how you will copy files recursively onto a target host?

The copy file in Ansible has a recursive parameter. If you have to copy file for a large number of files, then the synchronizing module is the best choice for it.

 

 

 

 

– synchronize:

src: /first/absolute/path

dest: /second/absolute/path

delegate_to: “{{ inventory_hostname }}”

How can you disable Cowsay?

If Cowsay is installed then executing your playbooks within Ansible is very smooth.
Even if you think that you want to work in a professional cow free environment, then you will have two options:
. Uninstall cowsay
. Setting up value for the environment variable, like below

Export ANSIBLE_NOCOWS=

How can you access a list of Ansible_Variables?

By default, Ansible gathers facts under machines under management. Further, these facts are accessed in Playbooks and in templates. One of the best ways to view a list of all the facts that are available in a machine, then you need to run the setup module in the ad-hoc way:

Ansible- m setup hostname

Once this statement is executed, it will print out a dictionary of all the facts that are available for that particular host. This is the best way to access the list of Ansible_variables.

How can you see all the variables specific to my host?

To see all the host-specific variables, that include all facts and other resources are:

Ansible – m debug- a “var=hostvars[‘hostname’]” localhost

How do you access a variable name programmatically?

By adding strings together, the variables names are built programatically like below format:

{{ hostvars[inventory_hostname][‘ansible_’ + which_interface][‘ipv’][‘address’] }}

‘inventory_hostname’ is a variable that represents the present host you are looping over.

How to configure a jump host for accessing servers that have no direct access?

We should set a ProxyCommand in the ansible_ssh_common_args inventory variable. For connecting to the relevant host, arguments defined in this variable are added to scp/ssh/sftp command line.

For example,

 

 

 

[gatewayed]

foo ansible_host=…

bar ansible_host=…

With the following contents, create the group_vars/gatewayed.yml

ansible_ssh_common_args: ‘-o ProxyCommand=”ssh -W %h:%p -q user@gateway.example.com”‘

 

When connecting to any hosts in the group gatewayed, Ansible will append these arguments to the command line.

Why don’t you ship in X format?

They are several reasons for not shipping in X format. In general, it caters towards maintainability. Within the market, they are tons of different ways to ship software and it is very tedious to support all of them.

What is that Ansible can do?

Ansible can do the following for us:
. Configuration management
. Application deployment
. Task automation
. IT orchestration

Please define what is Ansible Galaxy?

Ansible Galaxy refers to the website Galaxy where the users will be able to share all the roles to a CLI (Command Line interface) where the installation, creation, and managing of roles happen

Can you explain how to handle various machines requiring different user accounts or ports to log in?

Just by setting inventories in the inventory file, we can handle various machines requiring different user accounts or ports to log in.

For example, the following hosts have different ports and usernames:

 

 

 

[webservers]

asdf.example.com ansible_port= ansible_user=alice

jkl.example.com ansible_port= ansible_user=bob

You can specify connection type to be used by:

 

 

 

 

[testcluster]

localhost ansible_connection=local

/path/to/chroot ansible_connection=chroot

foo.example.com ansible_connection=paramiko

File them in a group_vars/ file.

Do you know what language Ansible is written in?

Ansible is written in Python and PowerShell

Please explain what is Red Hat Ansible?

Ansible and Ansible Tower by Red Hat, both are an end to end complete automation platforms which are capable of providing the following features or functionalities:

. Provisioning
. Deploying applications
. Orchestrating workflows
. Manage IT systems
. Configuration of IT systems
. Networks
. Applications

All of these activities are dealt by Ansible where it can help the business to solve the real time business problems.

 

What are Ansible server requirements?

You need to have a virtual machine with Linux installed, which has Python . version or higher.

 How to install Ansible on CentOS?

Step : Update your Control Node

yum update

Step : Install the EPEL Repository

yum install epel-release

Step : Install Ansible

yum install Ansible

How can you connect to other devices within Ansible?

Once, Ansible is installed and the basic setup has been completed, an inventory is created. This would be the base and one can start testing ansible. To connect to a different device then you have to use “Ping module”. This can be used as a simple connection test.

Ansible – m ping all

Can you build your own modules with Ansible?

Yes, we can create or own modules within Ansible.
It is an open-source tool which primarily works on Python. If you are good at programming in Python you can start creating your own modules in few hours from scratch and you don’t need to have any prior knowledge of the same.

. How can you find information in Ansible?

After completing the basic setup, one has to make sure to find out the module called “setup” module. Using this setup module, you will be able to find out a lot of information.

What does Fact mean in Ansible?

The term “Facts” is commonly used in Ansible environment. They are described in the playbooks areas where it displays known and discovered variables about the system.  Facts are used to implement conditionals executions and also used for getting ad-hoc information of the information.

You can see all the facts via:

$ ansible all- m setup

So if you want to extract only certain part of the information then you can use “setup” module where you will have an option to filter out the output and just get hold of the fact that you are in need of.

What is ask_pass in ansible?

The ask_pass is a control in Ansible Playbook.
This controls whether ansible playbook to prompt a password by default. Usually, the default behavior is no:

It is always set to ask_pass=True

If you are using SSH keys for authentication purposes then you really don’t have to change this setting at all.

Explain What is ask_sudo_pass

This control is very similar to ask_pass
The ask_sudo_pass controls the Ansible Playbook to prompt a sudo password. Usually, the default behavior is no:

ask_sudo_pass= True

One has to make sure and change this setting where the sudo passwords are enabled most of the time.

Explain what is ask_vault_pass?

Using this control we can determine whether Ansible Playbook should prompt a password for the vault password by default. As usual, the default behavior is no

ask_vault_pass= True

Explain Callback_plugin in Ansible?

Callbacks are explained as a piece of code in ansible environments where get is used call a specific event and permit the notifications.

This is more sort of a developer related feature and allows low-level extensions around ansible so that they can be loaded from different locations without any problem.

Explain Module utilities in Ansible?

Ansible provides a wide variety of module utilities which help the developers while developing their own modules. The basic.py is a module which provides the main entry point for accessing the Ansible library and using those as basics one can start off working.

Where is the unit testing is available in Ansible?

Unit tests for all the modules are available in .test/units/modules. Firstly, you have to setup your testing environment

Explain in detail about ad-hoc command?

Well, ad-hoc commands is nothing but a command which is used to do something quickly and it is more sort of a one-time use.  Unlike, the playbook is used for a repeated action which is something that is very useful in Ansible environment. But there might be scenarios where we want to use ad-hoc commands which can simply do the required activity and it is a nonrepetitive activity.

Is Ansible is an open-source tool?

Yes, Ansible is an open-source tool which is a powerful automation software tool that one can use.

Why you have to learn Ansible?

Ansible is more a tool for servers but does it have anything for networking. If you closely look into it, there is some support available in the market for networking devices. Using this tool, it will give you an overall view of your environment and also the knowledge how it works when it comes to network automation.

It is one of those tools where it is considered to be good to explore a new tool.

What are the advantages of Ansible?

Ansible has several advantages and strengths that include:

  • It has no agents but needs only SSH service working on the target machines.
  • It does not need many resources. Hence, there is a low overhead.
  • The only dependency of Ansible is Python, which is pre-installed in most of the systems.
  • Ansible is quite easy to understand.

What is CD/CI in Ansible?

CI and CD are practices followed in software development. CD abbreviates for Continuous Delivery while CI stands for Continuous Integration.

In CD, the software is built and delivered into production while in CI, different developers working on different modules upload the integrations on a daily basis. Ansible is the perfect tool for both CD and CI as it provides a stable infrastructure for setting the required environment and finally deploying the application.

What is Ansible Tower? What are its features?

Ansible Tower is a web-based solution that makes it easily accessible by IT teams. The main function of Ansible is to act as the hub for all automation tasks. The tower can be used for free for up to nodes.

Below are some of the primary features of Ansible tower:

  1. Job Scheduling.
  2. It helps to schedule the jobs to run later and set options for repetition.
  3. Roll Based Action Control: You can easily set up different roles and provide access to specific roles using Ansible tower.
  4. Fully Documented REST API: Using REST API, you can easily integrate Ansible with your already existing environment.
  5. Portal Mode: Ansible Tower offers an easy to use UI, which is useful for both newbie and experienced users.
  6. Cloud Integration: Ansible Tower has compatibility with most of the Cloud Environments such as Azure, RackSpace, and Amazon EC.

What is Idempotency?

Idempotency is an essential feature of Ansible, which ensures only the required changes occur. As an example, any task can be executed multiple times on the server, but it will not change the part, which is already working correctly. It can be implemented in Ansible using the attribute created.

What is Ansible Galaxy?

Ansible Galaxy is a storehouse of different Ansible roles through which you can share the content securely. It gets done through the Galaxy website, which lets the users find and share the content as per the role access. Ansible-Galaxy is the command that you can use to install the role, create a new role, remove the already existing role, and perform different tasks on the Galaxy website.

How to create encrypted files using Ansible?

The main command to manage the encrypted content is Ansible-vault. With this command, files can be encrypted and are used to edit, view, and decrypt the data. The new encrypted file is created by using Ansible-vault to create a command by just passing the file name. As an example; to create Hello.yml use below command:

$ Ansible-Vault create Hello.yml

What are tags?

When there is a large Ansible playbook, and you want to execute a part of it, it is possible using tags. Tags can be used on different structures in Ansible, but the most basic use of tags is with individual tasks. Tags can be applied to multiple tasks. This is done by using the –tags in the command line option. So all the tasks having this tag will get executed.

Can you filter the tasks with the help of tags?

Yes, the tasks can be filtered using the Ansible tags. This can be done in the following ways:

  1. You can use –tags option or –skip-tags option on the command-line tool.
  2. You can use TAGS_RUN and TAGS_SKIP options in the Ansible configuration settings.

What’s a handler?

A Handler is a regular playbook task, but the difference is that playbook tasks occur sequentially while a handler is executed when called by some event or a task. Handlers get executed once only once all the tasks in a specific play get completed. As an example, initiating a new service when the configuration setting changes or installation completes.

How to test Ansible projects?

Below three methods are available to test Ansible projects:

Asserts: Asserts matches how the test works in other languages such as Python. It verifies the system has reached the actual position where the test executes, not as a simulation, which you find in check mode. Asserts displays that the task did what it actually had to do.

Check Mode: The check mode in Ansible allows users to run the playbook without touching anything else. This implies that it will let the user know what the modules would have changed if the playbook was executed without check mode. Check mode is like a simulation only and is the least used option in Ansible.

Manual Run: It verifies that the system is in the state you would wish for. It is an easy method, but risky because the results might not be as same as in the production environment.

How to upgrade Ansible?

Upgrading Ansible is an easy task. You can do it using the below command:

sudo pip install Ansible==<version-number>

How do you access shell environment variables?

The existing variables of the controlling machine can be accessed by using the “env” lookup plugin. For example; to get the value of the management machine’s home environment variables, you can enter:

Local_home:”{{lookup(‘env’,’HOME’)}}”

What are the Ansible Server requirements?

You must have a virtual machine where Linux is installed if you use windows. It needs Python . or above version. If you manage these requirements, then you can continue with it.

What’s an ad hoc command?

Ad hoc command is a single task and quick command, which is not reusable. It is mainly used with tasks that get performed very rarely. For example, if you want to shut down all your computers in a lab before holidays, then it can be done with a single Ansible ad hoc command. The command gets executed on /usr/bin/Ansible command-line tool. Multiple tasks can be performed using an ad hoc command, such as copy files, reboot servers, manage users, manage packages, etc.

What is Configuration Management, and how does it help an organization?

Configuration Management is used to handle the updates systematically and maintain its integrity. With configuration management, all the updates made are maintained and tracked in the system and make sure that the system is up to date. Configuration Management helps organizations in the following ways:

  •         It helps to determine what changes are required with the changes in user requirements.
  •         Reverting back to the previous version, in case the updated version is faulty.
  •         It replaces the incorrect component because the user cannot find out this accurately.
  •         It updates an implementation because of changes in the requirements since the previous implementation.

What are the different components of Ansible? Explain Ansible architecture.

Ansible Automation Engine is the main component of Ansible, which directly communicates with the configuration management database, different cloud services, and users writing playbooks.

Ansible Automation Engine has the below components:

  •  Inventories: It contains the location of all the nodes, databases, and servers.
  •  APIs: Ansible APIs work like other APIs. The Ansible APIs help in commuting different cloud services and private or public services.
  • Modules: The Ansible modules are used for automating the varieties of tasks. These modules help in managing libraries, packages, files, system resources, and more. Ansible has approximately modules, which can automate almost everything in the Ansible environment.
  • Plugins: Ansible plugins help to execute Ansible tasks. Ansible offers around plugins that help in executing the task with ease.
  • Networking: Ansible helps in automating various networks as well as services by creating a Playbook.
  • Playbook: Playbook is the list of tasks that get executed sequentially. They follow the YAML format and are used for the automation of tasks.
  • CMDB: It is a database containing all the installed IT assets and the relationship between them.
  • Cloud: It consists of the remote server hosted online and used to store, manage, and process the data, instead of a local server.

What is the difference between playbook and play?

A playbook contains one or more plays, and a play contains one or more tasks.

Can we create modules in Ansible?

Yes, the modules can be created in Ansible. Ansible is an open-source tool that works on python language. Anyone who knows coding can create modules in Ansible.

What do you know about Ansible?

Answer: Ansible is the well-recognized open-source platform written and developed in Python language. This platform facilitates task automation, configuration management, and application deployment. It uses the SSH approach to deploy the application without any specific downtime.

Explain the use of Ansible?

Answer: automation is a crucial part of any software development process. The Ansible platform used in managing various IT infrastructure. It is also used for deploying software applications to remote nodes.

What are the major advantages of using Ansible?

Answer: Using Ansible can be beneficial in numerous ways. Then three of its advantages are mentioned below:

  • Agentless
  • Very low overhead and easy to learn
  • Great performance
  • Consistent with security
  • Reliable

Explain the Ansible Galaxy.

Answer: As Ansible facilitates bundling automation content. This makes it reusable. The Ansible galleries are needed here to share such Ansible roles. In simple words, the Ansible gallery is the tool which is merged with the Ansible. This integration creates the base directory structure.

What is continuous delivery in terms of Ansible?

Answer: It is the practice that involves delivering the software as soon as it is developed. For this, there is a need to use the versioning control system. Even in the live production system the software consistently updates.

How do Ansible works?

Answer: There are two main categories of server type in Ansible: the nodes and controlling machine. It simply uses the SSH protocol to deploy modules to nodes. These nodes stored in remote nodes interact with Ansible Machine. The Ansible has the capability to manage more than nodes in one single system.

Name different modules in Ansible.

Answer: In Ansible there are two major types of modules: core modules and extra modules.
Core Modules: These modules are the first preference of the Ansible team. The core modules come with Ansible software.
Extra Modules: The extra modules are reusable but for some reason, they always get a lower rate of response to issues. These are also maintained and managed by the Ansible Community. Although the extra modules are merged with Ansible but one can use it separately in the future.

Explain the Ansible tower.

Answer: The Ansible is the web-based center which is used for all kind of automation tasks. There is no requirement to install the daemons to connect with other controlling machines as it is an agentless model. The Ansible tower allows you free usage till ten nodes.

What is the difference between Ansible and Puppet?

Answer: Ansible: The Ansible has the simplest technology written in the YAML language. It can be quickly installed and deployed because of agent-less architecture. The Ansible supports automated workflow for continuous delivery.
Puppet: The puppet has complex technology in comparison to Ansible. This is written in Ruby language. To access this, it is important to learn Puppet DSL.

Give a brief about Ansible architecture.

Answer: The Ansible is highly based on the agent-less architecture. This structure enables you to connect your nodes. The pool of modules can dwell on any system without any daemons, server or the database. The SSH protocol enables it to execute these modules. It removes them as soon as work is done.

What’s the difference between the environment variable and variable name?

Answer: The variable name can be created by adding stings. On the other hand, for the access of environment variable, there is a need to access the existing variables. The variable name uses ipv for the available name. For remote environment variables {{ ansible_env.SOME_VARIABLE }} is used.

What are the things Ansible can do?

Answer: With the Ansible these are the following things one can do:

  • Deployment of application
  • Configuration management
  • Task automation
  • IT orchestration

What language Ansible is written in?

Answer: The Ansible is written in PowerShell and Python programming language.

Can you please explain the meaning of the red hat Ansible?

Answer: The red hat Ansible and Ansible both all the great automation platforms. The end to end complete automation of these platforms makes it capable to provide below-mentioned functionalities:

  • Application deployment
  • Provisioning
  • Management and configuration of IT systems
  • Orchestrating workflows

What are the requirements of the Ansible server?

Answer: For the window users, there is a need for the virtual machine in which the Linux should be installed. Otherwise, the Ansible requires Python . version or the higher one.

Is it possible to create own modules with Ansible?

Answer: Yes, the Ansible allows us to create the modules within it. As it is an open-source tool that majorly runs on Python. This means anyone who has little bit knowledge of programming can create their own modules without any problem within Ansible.

What’s the best way to generate crypto passwords for the user module?

Answer: The availability of mkpassword utility in Linux is the best option for generating the crypto passwords. For the OS X users who don’t

Explain the way to access shell environment variables in Ansible.

Answer: For accessing shell environment variables in Ansible users need to use the “env” lookup plugin. There are some codes that you have to write for this. The codes are mentioned below:

  • _ _ _
  • # …
  • vars :

Is it possible to keep secret data in the playbook?

Answer: Yes, it is possible to keep secret data in your Ansible content with the use of Vault in playbooks. With V mode you have to use some commands to hide sensitive data from others.’

Explain ad-hoc commands.

Answer: The ad-hocs are used to take action on the hosts without writing the playbooks. So, if you have to reboot the hosts in a specific group then there are two ways to do that. You can either create a new playbook or you can simply use the one-off ad-hoc command.

Explain the term “fact” in Ansible.

Answer: In the Ansible environment, “fact” is the most commonly addressed term. The facts are used by Ansible to get information about the host and store. The Ansible runs the setup modules to generate these facts.

What is the right way to copy files recursively onto a target host?

Answer: This “copy” module of Ansible has recursive parameters. You can also utilize “synchronize” modules if you need to perform more efficient for a huge number of files. It is important to use commands with “synchronize” modules.

Explain the meaning of Ansible tasks.

Answer: The Ansible tasks are majorly used to break up bits of configuration policy in little files. These small blocks of code that are used to automate any process.

Explain the Ansible role and what makes it different from the playbooks?

Answer: The Ansible role is completely another level of abstraction. These are used to organize playbooks. It provides an independent structure and a reusable collection of various things. It includes templates, files, variables, tasks, etc.

Why Ansible vaults are used?

Answer: The Ansible vaults are used to keep all your secret data safe. It facilitates the encryption of sensitive data but also integrates them into your playbooks. The files can either be entirely encrypted or unencrypted, the vault is implemented with file-level granularity. The Ansible vaults are very user-friendly.

Explain the features of the Ansible tower.

Answer: The Ansible towers display everything happening in the Ansible environment like inventory status, hosts and other recent activities. It also integrates the notifications about all the necessary updates. The multi-playbook workflow feature of Ansible tower makes it easier to chain all the playbooks. It is also useful for scheduling Ansible jobs.

How can you connect other devices within Ansible?

Answer: After installing Ansible on the controlling systems, one inventory file is created which particularly explains the connection between other nodes. The SSH protocol can be used to make a connection. If you want to check its connection, then you can use the ping module. The command to check this connection is:  ansible -m ping all

Does Ansible support AWS?

Answer: There are hundreds of modules present in Ansible that support AWS. It includes:

  • Autoscaling groups
  • CloudFormation
  • Virtual Private Cloud (VPC)
  • Security Groups
  • Relational Database Service (RDS)
  • CloudTrail
  • Elastic Cloud Compute (EC)

Which one is not a valid value of state argument of “file” module?

  1. file
  2. absent
  3. folder
  4. link

Answer: Folder

Which module can be utilized to copy files from a remote machine to a control machine?

  1. ping
  2. fetch
  3. copy
  4. move

Answer: fetch

If you do not need any facts from the host, what command would you use?

  1. gather_facts: no
  2. gather_facts: False
  3. both gather_facts: no or gather_facts: False
  4. gather_facts: y

Answer: gather_facts: no

Where is Inventory file located by default?

  1. /etc/ansible/hosts
  2. /etc/inventory
  3. /etc/configurations
  4. /etc/ansible

Answer: /etc/ansible/hosts

What is the default location for Ansible?

Answer:Default location for Ansible modules is /usr/share/ansible

Which module will you utilize to create a directory?

  1. File
  2. template
  3. fetch
  4. copy

Answer: File

Which module can be used to force a handler to run in between two tasks?

  1. Flush
  2. None of the options
  3. assest
  4. meta

Answer: meta

Which Ansible module is utilized for managing docker services and containers?

  1. docker_service
  2. docker_login
  3. docker_image
  4. docker

Answer: docker_service

Ansible has two types of servers. Select the appropriate answer from the given options.

  1. only node
  2. controlling machines and nodes

Answer: controlling machines and nodes

How to define the number of parallel processes while communicating to remote hosts?

  1. pipelining
  2. Forks
  3. become_method
  4. become

Answer: Forks

How can you reduce the number of SSH connections required?

  1. accelerate port
  2. pipelining
  3. forks
  4. become_method

Answer: pipelining

 Which configuration management is agentless

  • Ansible
  • Puppet
  • chef
  • CFEngine

Answer: Ansible

Ansible is generally referred to as what?

  • Infrastructure as code
  • Orchestration Engine
  • Configuration management
  • All the options

Answer: All the options

 How would you write comments on Jinja:

  1. {{}}
  2. {##}
  3. {%%}

Answer: {##}

 

What is the web-based interface used to access projects, inventories, job templates and jobs Ansible?

Answer: Ansible Tower Interface

How to Install Ansible in the Redhat Linux operating system?

Answer:

  • yum install ansible

Once the installation is completed, check the ansible version :

  •  ansible –version

If ansible package is not available in the default yum repositories, we need to manualy download.

How to set SSH-based access from Controller to Managed Nodes which is recommended by Ansible?

Answer: It provides passwordless auth to access the managed servers
In Control Server.
Step : Create user for ansible useradd -d /home/gangboard -m gangboard passwd gangboard
Step : Switch to ansible user
Step : su – gangboard
Step : Generate ssh key ssh-keygen -t rsa
Step : /home/gangboard/.ssh/id_rsa.pub => Public Key is in this file which needs to be copied to nodes ~/.ssh/authorized_keys

Perform the following setps on all Managed nodes.

Answer:
Step : Create user for ansible useradd -d /home/tadmin -m tadmin passwd tadmin
Step : Switch to ansible user su – tadmin
Step : Create .ssh directory mkdir .ssh
Step : Change permission to for .ssh chmod .ssh/
Step : Change Ownership to tadmin for .ssh chown tadmin:tadmin .ssh/
Step : create an authorized_keys file under .ssh and paste the public key from controller and save it
Step : cd .ssh/ , vi authorized_keys
 Step : Copy & paste the public key from the Controller server to this file [/home/tadmin/.ssh/id_rsa.pub] Now you able to access the server without a password.

How to run ansible command? Briefly explain?

Answer:
Running ansible command #ansible all -m ping

  • ansible => Ansible command
  • all       => Specifies the target to run the command.The target could an individual node or group(mentionedininventoryfile)orall(allthenodesintheinventory file). In this case all is used, which means that the command will be executed on all the nodes.
  •  -m     is the option that indicates that a module needs to be executed on remote nodes
  • ping is the name of a module. This module checks the ping status of the remote node. It has no attribute parameter (-a)

Explain the below output?

Answer:
Expected Outcome of the first command for QUE

node | SUCCESS =>

{

“changed”: false,

“ping”:”pong”

}

node | SUCCESS =>{ “changed”: false, “ping”:”pong”

}

Let’s understand on how to interpret the output
Explanation:

  • node  – This identified the node on which the task is done
  • SUCCESS  -Give a confirmation that the module was run successfully
  • changed”: false – ping module doesn’t do any modification on the remote node. It just checks the ping or node ON status. This the reason the changed status “false”.
  • ping”:” pong” -This a way ping module confirms the ping reply as“pong”.

Note: The output varies from module to module depending on how the module is.

How to write playbook, give example?

Answer: Below is the sample playbook:

name: Install Docker and  restart service hosts: webapp

become: true tasks:

name: Install Docker yum:

name: docker state: latest

name: Restart Docker  Service service:

name: docker state: restarted

Which command is used to run an ansible playbook?

Answer: command to run a playbook
 $ ansible-playbook -i hosts main.yml   

  •  -i- This is an option to specify to ansible to override the default inventory file and the inventory file specified.
  •  main.yml: This is the playbook file

What is the use of list-task in ansible?

Answer:  list-task: List all the tasks that will be executed when you run a playbook.

what is the use of –start-at-task in ansible?

Answer: start-at-task option, will start executing the task you specify and subsequent tasks are executed. The tasks above are skipped.

What is ansible variables?

Answer:

  • Variables are used to store values that can be later used in the playbook.
  •  Vars: is the tag to define a variable.

How are nodes,managed by a controlling machine over?

  1. They are managed by SSH and also the location of nodes are specified by controlling machine through inventory.
  2.  You can use ansible-vault to store sensitive information.
  3. True
  4. False

Answer: True

How to define handler in ansible playbook?

handlers:

name: Restart Docker Service

service:

name: docker

state: restarted

 

What is ansible roles?

Answer: Ansible roles consists of many playbooks. Roles are a way to group multiple tasks together into one container. These are reusable scripts.

How to create Ansible roles?

Answer: By using the following command we can create ansible roles
Ansible-galaxy init <rolename>

 

What are the key things required for the playbook?

Playbook may contains

  • Hosts
  • Variables (Optional)
  • Tasks

Explain about ansible modules?

Ansible modules are building blocks of ansible that are reusable scripts that are used by ansible playbooks.

How will start the services using ansible?

Answer: ansible    -m service  -a “name= httpd state=stopped” –become

What is configuration management?

Answer:  Configuration management is a process of continuous deployment and continuous delivery and continuous monitoring of the many servers in less period of time to achieve deliverables.

How to execute the created roles?

  • hosts: true
  • role:
  • – apache<rolename>

How to use existing tasks in Ansible?

by using  import_tasks:

How to use ansible-galaxy to download roles?

ansible-galaxy install username.rolename

. What is ansible jinja templates?

Answer: It is a file that contains all dynamic configurations parameters which will be having .j extension.

How to do role duplication and execution?

Answer: using allow_duplicates: true

What are the role dependencies?

Answer: Role default variables allow you to set the default variables for included or dependencies
Dependencies:

  • Role: tire
  • Role: brake

How to secure Ansible playbooks?

We have concept called ansible-vault .which encrypts the YAML files.

How to encrypt and decrypt Ansible playbooks?

Using ansible-vault encrypt and ansible-vault decrypt

How to change the existing password for ansible vault?

ansible-vault rekey

How to install Ansible on Linux?

First we need to install epel repo and then install ansible

  • Yum install epel-repo
  • Yum install ansible

Which module copies a dynamically generated file from control machine to target

  1. template
  2. file
  3. fetch
  4. copy

Answer: Template

How do you define ansible in the configuration management perspective?

Answer: Anything can be deployed/configured/installed by using ansible in the list of servers without even touching the server which actually doesn’t need any clients to be configured in all the server since it operates in ssh mode. That’s why it is called agentless, low overhead configuration management service

Do u know how to illustrate the working of Ansible ?

Answer: Yes, Ansible should be setup on a dedicated server which contains modules, inventories configured. Inventory contains the list of the target host which we want to connect/deploy/install/configure. That is simply a yaml file contained group name, server details. Modules are predefined in ansible which has the actual implementation definition on the ansible libraries. Host machines i.e target machines are connected via ssh and executes using python interpreter since all the definitions converted into python.

How do you define ansible is useful in the automation paradigm?

Answer: Automation is a sequence of operation which is done manually by the admin which is not possible over a thousands of server but that has to be managed from some place so ansible server is needed and all the server need not to be configured with some agent which takes operational headache all these can be overcome by the Ansible configuration management.

Do you know any API reference for Ansible ?

Answer: Yes, Ansible works on Rest API call which can be achieved by using ansible tower. It gives an option to use RBAC which is secured to access the secured ssh credentials

Will you be able to restart the target machines with Ansible?

Answer: Yes, we can restart the machines since it is OS operations, we have reboot module that has to be added in the tasks of the playbook to restart the machine

Do you know what are all the features of Ansible beyond automation?

Answer: Yes, It is not only for task automation, we can also perform beyond that. Cloud infrastructure automation can be performed using that, you can deploy the application to servers by using ansible, you can perform configuration management which is the main feature, and you can orchestrate multiple IT environment

How ansible is executing just by YAML script?

Answer: Actually Ansible is not written in YAML, it has written in python programming and Powershell. So, YAML is getting converted to it that’s how it works

Do you know ansible cannot be considered as opensource?

Answer: That is completely wrong, Ansible is opensource whereas Redhat Ansible is customized by Redhat

Server requirement for Ansible how will it look like ?

Answer: Here Ansible server should have linux installed and python version should be . or higher.

So do you have an option do customize you own ansible modules?

Answer: Yes, Since it is an opensource tool, you have an option to customize it. But the clear requirement is you should be a good programmer so that you can get started to develop your own module for Ansible. You don’t need any extraordinary prior experience to build your own module

Do you know the other way around to perform ansible operations without writing playbooks ?

Answer: We have an option to write our single task and execute it without even writing playbook that is called ad-hoc commands. Which is like normal Ansible CLI commands which passes required modules and arguments for the modules, and the targeted host groups in a single command.

Do you know how do we parameterize the arguments required for the module ?

Answer: This can be done in the playbook or roles when you write it, you have to use variables and its value under vars section in playbook. If it is roles, it has to be in the vars folder and main.yaml file.
Example:
vars:

  • myvar: value
  • myvar: value

 

Will you be able to see the host machine all variables using ansible?

Answer: Yes we have a module called debug module. Either you can write playbook or adhoc commands, both the way it can be achieved.  Pass the arguments as ‘var=hostvars[inventory_hostname] localhost’ this gets the variables of machines

Could you differentiate Roles and Playbooks?

Answer: Roles are written as a collection which contains tasks, vars, default vars, metadata information, handlers, files all separated in different folder whereas in playbook which contains all in a single file. Roles can be shared with ansible galaxy so that others can easily pull it without any dependency

Differentiate ask_pass and ask_sudo_pass

Answer: Yes Ask_pass default value is actually no, if you want it to enable explicitly you can set it as True. This enables option to ask password whereas ask_sudo_pass will be prompted when sudo password is required to entered by the user.

Do you know how do we make use of our ansible script reusable or redistributable ?

Answer: Yes roles is the only way we can use this. Roles ensures that can be distributed or redistributed with the updated content . This contains document which says how to use the roles.

Do we hav option to copy a file from my ansible server to all server ?

Answer: Yes, we have option to copy files from ansible servers to all the servers. We have file module which does that. You can also copy files with changing or without changing permissions, owners, groups etc.

How can u encrypt ansible passwords or any data ?

Answer: We have ansible vault which protects all the confidential information which is needs to be protected from the end user.

How will you ensure the targeted server connection is established ?

Answer: We can use ping module which tries to ping all the servers in the inventory files. This will give ‘pong’ as response if the server is pingable. The ad-hoc commands can be used to test whether the servers are reachable with ansible server or not. The syntax of the commands is
‘ansible -m ping <groupname>’

Please define what is Ansible Galaxy?

Answer: Ansible Galaxy is the website, where we can share all the ansible roles

How can you install Ansible on Amazon EC instance?

Answer: Ansible can be installed on Amazon EC Instance using the Yum Install command.

How can you install Ansible on Amazon EC instance?

Answer: Ansible can be installed on Amazon EC Instance using sudo pip  Install ansible command.

How can you take backup of configuration in Ansible?

Answer: Use copy module in Ansible we can backup the file to remote locations

What module can be utilized to stop a playbook execution for a specific period?

  1. Sleep
  2. Pause
  3. Stop
  4. Suspend

Answer: Pause

What is Ansible Tower?

Answer: Ansible tower is commercial products from Redhat . It is used to simplify the job of ansible automation. We can also has lot of options like monitoring

What is Configuration Management (CM) Practices?

Answer: Configuration Management is the practice of managing the complete Infrastructure as a code ( IAC), it helps to automate the provisioning, deprovision, update, manage, deprovisioning of infrastructure which include OS, Application, update as an code. The organization is using Ansible , Terraform likes tool for their CM.

What are the basic terminologies used in Ansible.

Answer: The most basic terminology used in Ansible are

  • Controller Machine: It is the main controller machine, which manages all the host
  • Playbook: An YAML script, which contains the tasks
  • Task: Task is the single piece of work like install http
  • Inventory: The server can be gopura together know as inventory
  • Module: It is an executable set of tasks.
  • Role: An Ansible role is a pre-configured way forgetting organize the playbooks

 

So, this brings us to the end of the Ansible Interview Questions blog.This Tecklearn ‘Top Ansible Interview Questions and Answers’ helps you with commonly asked questions if you are looking out for a job in Ansible or DevOps Domain. If you wish to learn Ansible and build a career in DevOps domain, then check out our interactive Configuration Management using Ansible Training, that comes with 24*7 support to guide you throughout your learning period.

https://www.tecklearn.com/course/configuration-management-using-ansible/

Configuration Management using Ansible Training

About the Course

Tecklearn has specially designed this Configuration Management using Ansible Training Course to advance your skills for a successful career in this domain. The course will cover different components of Ansible and how they are used in software development operations.  You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Ansible.

Why Should you take Configuration Management using Ansible Training?

  • The average Ansible salary in USA is $136,500 per year or $70 per hour. Entry level positions start at $100,000 per year while most experienced workers make up to $187,500 per year.
  • Wells Fargo, Capital One, Apple, CISCO & many other MNC’s worldwide use Ansible across industries.
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Configuration Management using Ansible

  • What is Ansible?
  • Ansible vs Puppet
  • Ansible Architecture
  • Ansible Installation
  • Setting up Master Slave using Ansible
  • Configuring Ansible Roles
  • Write Playbooks
  • Applying configuration using Ansible
  • Hands on

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

 

0 responses on "Top Ansible Interview Questions and Answers"

Leave a Message

Your email address will not be published. Required fields are marked *