0% found this document useful (0 votes)
598 views

Ansible Interview Questions and Answers

Ansible is a configuration management tool that has several advantages including not requiring agents on target machines, having low overhead since it only needs Python and SSH, and being easy to understand. It can be used for continuous integration (CI) and continuous delivery (CD) by providing a stable infrastructure for deploying applications. Ansible works by having controlling machines that run playbooks using SSH to execute modules on nodes. Playbooks are written in YAML format and are Ansible's primary method for automating tasks. Ansible Tower provides a web interface and additional features like job scheduling and cloud integration.

Uploaded by

gururaj_hebbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
598 views

Ansible Interview Questions and Answers

Ansible is a configuration management tool that has several advantages including not requiring agents on target machines, having low overhead since it only needs Python and SSH, and being easy to understand. It can be used for continuous integration (CI) and continuous delivery (CD) by providing a stable infrastructure for deploying applications. Ansible works by having controlling machines that run playbooks using SSH to execute modules on nodes. Playbooks are written in YAML format and are Ansible's primary method for automating tasks. Ansible Tower provides a web interface and additional features like job scheduling and cloud integration.

Uploaded by

gururaj_hebbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Ansible Interview Questions and Answers

Q1. 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.
Q2. 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.
Q3. How does Ansible work?
Ansible gets usually divided into two types of servers called Controlling
Machines and Nodes. It is present on the controlling machines, which
further connects to different nodes. A playbook gets run by Ansible on
controlling machines that execute the Ansible modules with SSH and
removes these modules when execution completes. The controlling
Machines manage all the nodes; hence no third party tool is required.
Q4. What is an Ansible Playbook?
The playbook is a file where code for Ansible gets written. The Playbook
follows the YAML format and is an essential feature of Ansible. The files
contained in the Playbook run sequentially. Overall, the Playbook is the
building block of Ansible.

Q5. 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 10 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 EC2.
Q6. 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.
Q7. 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.

Q8. 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

Q9. What is an ask_pass module?


ask_pass is required when password-based authentication is required to
connect to the nodes. Simply add—an ask-pass option with Ansible
command. When this option is used, Ansible will prompt for a password
from the user to connect.
Q10. 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.
Q11. 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.
Q12. 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.

Q13. 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.

Q14. How to upgrade Ansible?


 Upgrading Ansible is an easy task. You can do it using the below
command:
sudo pip install Ansible==<version-number>

Q15. When do you use {{ }}?


This is one of the basic rules of Ansible: “use {{ }} except when:”

Q16. 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’)}}”

Q17. What are the Ansible Server requirements?


You must have a virtual machine where Linux is installed if you use
windows. It needs Python 2.6 or above version. If you manage these
requirements, then you can continue with it.
Q18. What is the difference between a variable name and an
environment variable?
Variable Name Environment Variable

To create variable names, you have to To access environment variables, you need already existing
add strings variables

By adding strings, you can create You should refer advanced Ansible Playbook to create
several variable names environment variables

For variable names, use the ipv4 For remote environment variable, use
address {{ Ansible_envSOME_VARIABLES}}
Q19. Compare Ansible with Chef. 
Parameters Ansible Chef

No special set up is required for the The server runs on the master machine, and
Installation and
client machine. The set up is very the client agent runs on the client machine.
Set up
simple. Therefore, the set up is a little tricky.

It uses YAML, which resembles the


Configuration It uses Ruby domain-dependent language.
English language and is easy to
Management Therefore, knowledge of Ruby is a must.
understand.

It uses static and dynamic


Statics-Dynamic The user has to register the host on the
inventories, e.g., INI file having hosts
Inventories chef server.
present in different sections.

For basic operations, the amount is


It is more affordable, and the amount to
Pricing $10,000 / year for 100 nodes and
pay is $137 per node.
$14,000 in a premium package.

Q20. 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.
Q21. 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.

Q22. 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 450
modules, which can automate almost everything in the Ansible
environment.
 Plugins: Ansible plugins help to execute Ansible tasks. Ansible
offers around 100 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.

Q23. What is the difference between playbook and play?


A playbook contains one or more plays, and a play contains one or more
tasks.
Q24. How can you copy files on the target host recursively?
Files can be copied to the host using the copy module. There is a recursive parameter that
copies all the files present in a directory. The synchronize module is also used for this
purpose. You simply have to mention the source and destination directories.

Q25. 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.
Also Read: Full Stack Developer Interview Questions

You might also like