Ansible Interview Questions And Answers

TOP 150+ Ansible Interview Questions And Answers

Latest Ansible Interview Questions And Answers

Ansible Interview Questions And Answers are as follows-

1) What is Ansible?

Ansible is an open-source IT engine that automates application deployment, cloud provisioning, intra service orchestration, and other IT tools.

Ansible is very easy to deploy because it does not use any agents or custom security infrastructure on the client-side, and by pushing modules to the clients. These modules are executed locally on the client-side, and the output is pushed back to the Ansible server. It can easily connect to clients using SSH-Keys.

2) What are the uses of Ansible?

Ansible is free to use by everyone.

Ansible is very consistent and lightweight, and no constraints regarding the operating system or underlying hardware are present.

It is very secure due to its agentless capabilities and open SSH security features.

Ansible does not need any special system administrator skills to install and use it.

Ansible has a smooth learning curve determined by the comprehensive documentation and easy to learn structure and configuration.

Its modularity regarding plugins, inventories, modules, and playbooks make Ansible perfect companion orchestrate large environments.

3) What is Ansible Tower?

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

4) What is Ansible Galaxy?

Ansible Galaxy is a galaxy website where users can share roles and to a command-line tool for installing, creating, and managing roles.

Ansible Galaxy gives greater visibility to one of Ansible’s most exciting features, such as application installation or reusable roles for server configuration. Lots of people share roles in the Ansible Galaxy.

5) What is Ansible Modules?

Ansible modules are discrete units of code which can be used from the command line or in a playbook task.

The modules also referred to as task plugins or library plugins in the Ansible.

Ansible ships with several modules that are called module library, which can be executed directly or remote hosts through the playbook.

Users can also write their modules. These modules can control like services, system resources, files, or packages, etc. and handle executing system commands.

6) How does Ansible work?

Ansible works by connecting to the nodes and pushing out a small program called Ansible modules to them. Then Ansible executed these modules and removed them after finished. The library of the modules can reside on any machine, and there are no daemons, servers, or databases required.

The Management Node is the controlling node that controls the entire execution of the playbook. The inventory files provide the list of hosts where the Ansible modules need to be run. The Management Node makes an SSH connection and executes the small modules on the host’s machine and install the software.

7) What are the Ansible Server requirements?

If you are a windows user, then you required to have a virtual machine in which Linux should be installed. And it requires python 2.6 version or higher.

8) What are the variables in Ansible?

The variable is very similar to using the variables in a programming language. It helps you to assign a value to a variable and use it anywhere in the playbook. You can put the conditions around the value of the variables and use them in the playbook accordingly.

9) What is Ansible Task?

Ansible Task allows us to break up bits of configuration policy into smaller files. These are the block of code which can be used to automate any process.

10) Explain the basic terminologies or concepts in Ansible?

Some basic terms which are commonly used in Ansible, such as:

Controller Machine: The Controller machine is used to provisioning the servers, which is managed. This is the machine where Ansible is installed.

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

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

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

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

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

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

Facts: Facts are global variables which are store details about the system, such as network interfaces or operating system.

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

11) What are Ad-hoc commands?

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

ansible host -m netscaler user=ansiuser password=ansipass”

The above Ad-hoc command accesses the NetScaler module to disable the server.

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

Executes the following commands to access a variable of the first host in a group:

{{ hostvars[groups[‘webservers’][0]][‘ansible_eth0’][‘ipv4’][‘address’] }}

This command is accessing the hostname of the first machine in the webservers group. If you are doing this by a template, then use the jinja2 ‘#set’, or you can use set_fact

13) How to keep secrete data in a playbook?

The following command is used to keep verbose output but hide the sensitive information from others who would like to be able to see the output.

–   name: secrete task

shell: /user/bin/do_somthing -value={{secrete value}}

no_log: True

Also, the no_log attribute can apply to an entire play.

–   hosts: all

no_log: True

14) What are Ansible Vaults, and why are they used?

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

Vault is implemented with file-level granularity, where the files are completely encrypted or unencrypted. It uses the same password for encrypting as well as decrypt the data, which makes Ansible vault user-friendly.

15) What is the way to access shell environment variables in Ansible?

In Ansible, if you want to access existing variables, then you need to use the ‘env‘ lookup plugin.

For example, you want to access the value of the Office environment on the management machine, as shown in the following command, such as:

# …


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


{{ ansible_env.SOME_VARIABLE }}


16) Who you can copy file recursively onto a target host?

The “copy” module has a recursive parameter. Therefore, if you want to perform more efficient for a large number of files, then the “synchronize” module is the best option for doing this task.

17) How do you 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. Follow the following code to see how do set the path, such as:


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

SOME: value

18) How can you see all variables for a host?

You can see all the variables using the host vary variable. It stores host variables with the hostname as key. For example, to look at the variables defined for localhost, you can run the following command, such as:

ansible -m debug -a “var=hostvars[inventory_hostname]”

19) What is the difference between the Variable Name and Environment Variable in Ansible?

Variable Name Environment Variable
You need to add strings to create variable names. You need existing variables to access environment variables.
You can easily create multiple variable names by adding strings. To create environment variables, you must refer to the advanced Ansible playbook.
Use the IPV4 address for variable names. Use {{ansible_env.SOME_VARIABLE}} for remote environment variables.


20) What is RedHat Ansible?

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


Deploying applications

Orchestrating workflows

Manage IT systems

Configuration of IT systems



All of these activities are dealing with Ansible, where it can help the business to solve real-time business problems.

21) 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.

22) 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.

23) State the requirements for the Ansible server.

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

24) 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.

25) How do you set up Ansible?

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

26) 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.

27) 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.

28) 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

29) 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.

30) 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.

31) 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.

32) 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.

33) 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.

34)  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.

35) 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.

36) How do you test Ansible projects?

There are three testing methods available:


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.

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

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.

37) Explain how you can disable cowsay?

If cowsay is installed then executing playbooks inside the Ansible you can disable coway by using following  options:

Uninstall cowsay

Setting up value for the environment variable


38) How Can you submit a change to the Documentation in Ansible?

Documentation for Ansible is kept in the project git repository. It contains complete instructions for contributing can be found in the docs.

39) What Is the Best Method to Make Content Reusable/redistributable?

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.

40) What’s the method to check the inventory vars defined for the host?

For that use this command:

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

41) State the difference between Variable name and Environment Variables.

Variable Name Environment Variables
It can be built by adding strings. To access the environment variable, you need to access existing variables.
{{ hostvars[inventory_hostname][‘ansible_’ + which_interface][‘ipv4’][‘address’] }} # … vars: local_home: “{{ lookup(‘env’,’HOME’) }}”
Allows to add strings To set environment variables, we need to see the advanced playbooks section.
Ipv4 address type use for Variable names we use the ipv4 address. For Remote environment variables, use {{ ansible_env.SOME_VARIABLE }}


42) How do you see all variables for a host?

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;

ansible -m debug -a “var=hostvars[inventory_hostname]

43) Explain modules in ansible

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.

There are two different types of modules in Ansible:

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.

44) 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:

Simple: Uses a simple syntax written in YAML called playbooks.

Agentless: No agents/software or additional firewall ports that you need to install on the client systems or hosts which you want to automate.

Powerful and Flexible: Ansible’s capabilities allow you to orchestrate the entire application environment regardless of where it is deployed.

Efficient: Ansible introduces modules as basic building blocks for your software. So, you can even customize it as per your needs.

45) How is Ansible different from Puppet?

Metrics Ansible Puppet

Ease of set up



Configuration language


Pricing nodes

Highly available


Easy management

Highly scalable




Highly available

Comparatively hard to set up

Not very easy

Highly scalable





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

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 450 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 100s 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.

47) 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 100s 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.

48) 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.

49) Compare Ansible with Chef. 

Metrics Ansible Chef

Ease of set up



Configuration language


Pricing nodes

Highly available


Easy management

Highly scalable




Highly available

Not very easy

Not very easy

Highly scalable





50) 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


port_Tomcat : 8080

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

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

Variable name Environment variable
You need to add strings to create variable names

You can easily create multiple variable names by adding strings

We use the ipv4 address for variable names

You need existing variables to access environment variables.

To create environment variables we must refer advanced Ansible playbook

We use {{ ansible_env.SOME_VARIABLE }} for remote environment variables.


52) 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 Jinja2 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.

53) List cons and pros of Ansible?

Below is the list of Pros of Ansible which is self-explanatory:

  • Easy installation and initial setup
  • Syntax and workflow are fairly easy to learn for new users
  • Easy remote execution, and low barrier to entry
  • Highly secure using SSH
  • Suitable for environments designed to scale rapidly
  • Shares facts between multiple servers, so they can query each other
  • Powerful orchestration engine. Strong focus on areas where others lack, such as zero- downtime rolling updates to multi-tier applications across the cloud
    Sequential execution order
  • Supports both push and pull models
  • Lack of master eliminates failure points and performance issues. Agent-less deployment and communication is faster than the master-agent model


  • Underdeveloped GUI with limited features
  • Requires root SSH access and Python interpreter installed on machines, although agents are not required
  • Increased focus on orchestration over configuration management
  • SSH communication slows down in scaled environments
  • The syntax across scripting components such as playbooks and templates can vary


54) 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.

55) 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.

56) 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

57) What language Ansible is written in?

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

58) 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


Management and configuration of IT systems

Orchestrating workflows

59) 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.

60) 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

61) Does Ansible support AWS?

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

Autoscaling groups


Virtual Private Cloud (VPC)

Security Groups

Relational Database Service (RDS)


Elastic Cloud Compute (EC2)

62) Where is Inventory file located by default?


63) What is the default location for Ansible?

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

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

ANS: meta

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

ANS: docker_service

66) Ansible has two types of servers. What are those?

ANS: controlling machines and nodes

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





Answer: Forks

 68)  What is the default forks value in configuration file?




depends upon hosts in the inventory

Answer: 5

 69) How can you reduce the number of SSH connections required?

accelerate port




Answer: pipelining

70) Which configuration management is agentless





Answer: Ansible

71) Ansible is generally referred to as what?

Infrastructure as code

Orchestration Engine

Configuration management

All the options

Answer: All the options

72)  How would you write comments on Jinja2:




Answer: {##}

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

Answer: Ansible Tower Interface

74) How to Install Ansible in the Redhat Linux operating system?


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.

75) 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 1: Create user for ansible useradd -d /home/gangboard -m gangboard passwd gangboard
Step 2: Switch to ansible user
Step 3: su – gangboard
Step 4: Generate ssh key ssh-keygen -t rsa
Step 5: /home/gangboard/.ssh/ => Public Key is in this file which needs to be copied to nodes ~/.ssh/authorized_keys

78) Perform the following setps on all Managed nodes.

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

76)  What is inventory in Ansible and how to update it?


The inventory files contain a host list of managed nodes, when ansible accessing the client it look into inventory.

The default inventory file for Ansible is located under /etc/ansible/hosts

This default inventory lookup can be overridden using -i option providingthe custom inventory file

 Example: ansible -i cmdb.inv main.yml Update default Inventoryfile/etc/ansible/hosts (as rootuser) [clients]



77) How to run ansible command? Briefly explain?

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)

78) Explain the below output?

Expected Outcome of the first command for 4 QUE

node1 | SUCCESS =>


“changed”: false,



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


Let’s understand on how to interpret the output

node1 – 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

79) What is ansible-playbook?

Answer: The playbook is a .yml file that contains a piece of code called a module. You can have multiple tasks in a playbook and these tasks would be executed by Ansible. Playbooks have a list of remote hosts, user variables, tasks, handlers inside it.

80) 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

81)  which command is used to run an ansible playbook?

Answer: command to run a playbook
 $ ansible-playbook -i hosts main4.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

82) 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.

83)  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.

84)  What is ansible variables?


Variables are used to store values that can be later used in the playbook.

Vars: is the tag to define a variable.

85) How are nodes,managed by a controlling machine over?

They are managed by SSH and also the location of nodes are specified by controlling machine through inventory.

You can use ansible-vault to store sensitive information.



Answer: True

86) Why handlers are used in the playbook?


Handlers are similar to tasks in executing modules. The only difference is that the handlers need to be called explicitly.

Handlers will be called only on successful change of the state i.e. when the task has done some changes on remote nodes aka.  state: changed

Within tasks, handlers will be called using “notify” tag. Name given in notify should  exactly match  as in the -name tag inside handlers

87)  How to define handler in ansible playbook?



name: Restart Docker Service


name: docker

state: restarted

88)  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.

89) How to create Ansible roles?

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

90) What are the key things required for the playbook?

Answer: Playbook may contains


Variables (Optional)


91) What are the advantages of Ansible?

Answer: Ansible is agentless which means it doesn’t require any node machine to configure. It uses YAML to create playbooks which is easy to understand.

92) Explain about handlers in Ansible?

Answer:  If we want to execute tasks whenever something changed in the configuration files then we need to use “notify” in the playbook. For example if we want to restart apache whenever the configuration file changes.

93) What is inventory in ansible?

Answer: /etc/ansible/hosts file called as inventory. It contains the group of the server name or IP’s.

94) Explain about ansible modules?

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

95) How will start the services using ansible?

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

96) 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.

97) How to execute the created roles?

Answer:  —

hosts: true


– apache<rolename>

98) How to use existing tasks in Ansible?

Answer: by using  import_tasks:

99) How to use ansible-galaxy to download roles?

Answer: ansible-galaxy install username.rolename

100) What is ansible jinja2 templates?

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

101) How to do role duplication and execution?

Answer: using allow_duplicates: true

102) What are the role dependencies?

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

Role: tire

Role: brake

103) How to secure Ansible playbooks?

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

104) How to encrypt and decrypt Ansible playbooks?

Answer: Using ansible-vault encrypt and ansible-vault decrypt

105) How to change the existing password for ansible vault?

Answer: ansible-vault rekey

106) How to install Ansible on Linux?

Answer:  First we need to install epel repo and then install ansible

Yum install epel-repo

Yum install ansible

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





Answer: Template

108) 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

109) 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.

110) 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.

111) 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

112) 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

113) 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

114) 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

115) Do you know ansible cannot be considered as opensource?

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

116) Server requirement for Ansible how will it look like ?

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

117) 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

118) 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.

119) 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.

myvar1: value

myvar2: value

120) 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

121) 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

122) 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.

123) 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.

124) Do we have 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.

125)  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.

126) 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>’

127) What are playbooks in ansible ?

Answer: Playbooks are the scripts that we use in Ansible. They are used as building blocks that you can use to execute on remote machine. The scripts will contain the instructions that needs to be executed on the remote machines. This script follows a yaml format so you have to very careful with the indentation.

128)  What are ad-hoc commands ?

Answer: Ad-hoc commands in ansible is another way of executing commands on remote machines. They are your one time commands that will not be saved for future use. The other way that you can execute commands on remote machines is by writing a playbook.

129) What is an inventory file ?

Answer: Inventory file is the file that will be used by the playbooks to identify the IP addresses of the remote machines to execute the playbooks. This file is also known as the host file and will be available in “/etc/ansible/hosts” location. Whenever you want yo execute a playbook you will need to provide the IP addresses in the inventory file.

130) What is ansible tower ?

Answer: Ansible tower is the UI version of Ansible. Ansible tower provides an web user interface that you can use to execute the playbooks. Ansible tower makes it easier to use ansible for all the IT needs.

131) 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.

Q132) 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 .

Q132) 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.

Q133) 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.

Q134) 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

Q135) What is Configuration Management (CM) Practices?

Answer: Configuration Management is the practice of managi8ng 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.

Q135) 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

Q136) Please define what is Ansible Galaxy?

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

Q137) How can you install Ansible on Amazon EC2 instance?

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

Q138) How can you install Ansible on Amazon EC2 instance?

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

Q139) How can you take backup of  configuration in Ansible?

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

Q140) Is there a web interface / REST API / etc?

Yes, Ansible, Inc makes a great product that makes Ansible even more powerful and easy to use.

Related Posts:

For more Interview Questions And Answers click here