Ansible Interview Questions
Ansible Interview Questions
com/
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) What Is Ansible?
Ansible is a configuration management system. It is used to set up and manage infrastructure and
applications. It allows users to deploy and update applications using SSH, without needing to
install an agent on a remote system.
Ansible is used for managing IT infrastructure and deploy software apps to remote nodes.
For example, Ansible allows you to deploy as an application to many nodes with one single
command. However, for that, there is a need for some programming knowledge to understand
the ansible scripts.
Ansible can communicate with configured clients from the command line by using ansible
command. It also allows you to automate configuration by using ansible-playbook command. To
create the base directory structure, you can use a tool bundled with Ansible which is known as
ansible-galaxy.
Command:
In Ansible, if you want to access existing variables, the user needs to use the ‘env’ lookup plugin.
Example, to access the value of the Office environment on the management machine:
---
# ...
vars:
local_home: "{{ lookup('env','Office') }}"
I
{{ ansible_env.SOME_VARIABLE }}
https://www.guru99.com/
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6) What is the code you need to write for accessing a variable name?
{{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }}
The method of using hostvars is important because it’s a dictionary of the entire namespace of
variables. ‘inventory_hostname’ variable specifies the current host you are looking over in the
host loop.
If cowsay is installed then executing playbooks inside the Ansible you can disable coway by using
following options:
1. Uninstall cowsay
2. Setting up value for the environment variable
export ANSIBLE_NOCOWS=1
8) Explain how you can copy file recursively onto a target host?
The "copy" module has a recursive parameter. However, if you want this to perform more
efficient for a large number of files, then “synchronize” module is the best option for you.
Documentation for Ansible is kept in the project git repository. It contains complete instructions
for contributing can be found in the docs.
You can read everything about “Roles” in the playbooks documentation section. This helps to
make playbook content self-contained and shareable with other ansible users.
https://www.guru99.com/
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
It can be built by adding strings. To access the environment variable, you need
to access existing variables.
Ipv4 address type use for Variable names we use the For Remote environment variables, use {{
ipv4 address. ansible_env.SOME_VARIABLE }}
11) What is Ansible Tower?
Ansible tower is a tool which makes Ansible very easy to use. It acts as a hub for the task
automation. The tower is free for usage till 10 nodes.
12) What’s the method to check the inventory vars defined for the host?
13) State the difference between Variable name and Environment Variables.
You can think of ad-hoc commands as a way for us to take actions on our hosts without writing a
playbook. For example, if we want to reboot all hosts in a particular group(webservers). Then you
can write a playbook or simply run a one-off ad-hoc command.
You can think of ansible facts as a way for ansible to get information about a host and store them
in variables for easy access. This information stored in predefined variables are available to use in
the playbook. To generate facts, ansible runs the setup module.
You can see them using the host vary variable. This stores host variables with the hostname as
key. For example, to look at the variables defined for localhost, you can run;
Modules in Ansible are idempotent. From a RESTful service standpoint, for the operation to be
idempotent, clients can perform the same result by using modules in Ansible. Multiple identical
requests become a single request.
• Core modules
• Extras modules
Core Modules
The Ansible team maintains these types of modules, and they will always ship with Ansible
software. They will also give higher priority for all requests than those in the “extras” repos.
Extras Modules:
These modules currently is bundled with Ansible but might available separately in the future.
They are also mostly maintained by the Ansible community. These modules are still usable, but it
can receive a lower rate of response to issues and pull requests.
In ansible, Tests can be added either in new Playbooks or to existing Playbooks. Therefore, most
of the testing job offers a clean hosting each time. By using this testing methodology, you need to
make very little to no code changes.
Project
Test Management Business Analyst Ethical Hacking PMP
Management
Software
Jenkins Agile Testing RPA JUnit
Engineering