Top 50 Ansible interview questions and answers

Ansible interview questions and answers

Table of Contents

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

Q2) What are the advantages of using Ansible?

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

  • Agentless
  • Very low overhead
  • Good performance

Q3) 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 100’s of nodes by a single command, here ansible comes into the picture, with the help of Ansible you can deploy as many 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 1-4 and covers the following topics.

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.

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

Q6) Is Ansible a Configuration management tool?

Configuration management is the practice to handle updates and manage the 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.

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

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

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

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

Q10) 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 1950s run of ‘Galaxy’ magazine. My favorite 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 a school that made the 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.

Q11) 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 favor 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 1979 can be read online.

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

1. Controlling machines

2. Nodes Ansible is an agentless tool so it doesn’t require any mandatory installations on remote nodes. So there are 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 an 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.

Q13) What does Ansible offer?

Ansible offers:

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

Q14) 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 full access to the .Net framework, which is primarily used by internal components and modules.

Q15) Do we have any Web Interface/ Rest API etc fo

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

Q16) 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 10 nodes.

Q17) What are the features of the Ansible Tower?

Features of the Ansible Tower are:

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

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

Q19) How do you access Shell Environment Variables?

If you are just looking to access the existing variables then you can use the “env” lookup plugin.

For example:

Accessing the value of Home environment variable on management machine:


Q20) How can you speed up management inside EC2?

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

Q21) What are the features of Ansible?

It has the following features:

Agentless – Unlike puppet or chef there is no software or agent managing the nodes. Python – Built on top of python which is very easy to learn and write scripts and one of the robust programming languages.

SSH – Passwordless network authentication which makes it more secure and easy to set up.

Push architecture – The core concept is to push multiple small codes to the configure and run the action on client nodes.

Setup – This is very easy to set up with a very low learning curve and any open source so that anyone can get hands-on.

Manage Inventory – Machines’ addresses are stored in a simple text format and we can add different sources of truth to pull the list using plugins such as Openstack, Rackspace, etc.

Q22) Explain Infrastructure as Code?

Infrastructure as Code or IaC is a process that DevOps teams should follow to have a more organized way of managing the infra. Instead of some throwaway scripts or manually configuring any cloud component, there should be a code repo where all of these will lie and any change in configuration should be done through it. It is wise to put it under source control also. This improves speed, consistency, and accountability.

Q23) What is Ansible Galaxy?

Galaxy is a repository of Ansible roles that can be shared among users and can be directly dropped into playbooks for execution. It is also used for the distribution of packages containing roles, plugins, and modules also known as collection. The ansible-galaxy-collection command implements similar to init, build, install, etc like an ansible-galaxy command.

Q24) Explain Ansible modules in detail?

Ansible modules are like functions or standalone scripts which run specific tasks idempotently. The return value of these are JSON string in stdout and input depends on the type of module. These are used by Ansible playbooks.
There are 2 types of modules in Ansible:

Core Modules

The core Ansible team is responsible for maintaining these modules thus these come with Ansible itself. The issues reported are fixed on priority than those in the “extras” repo.

Extras Modules

The Ansible community maintains these modules so, for now, these are being shipped with Ansible but they might get discontinued in the future. These can be used but if there are any feature requests or issues they will be updated on low priority.

Now popular extra modules might enter into the core modules anytime. You may find these separate repos for these modules as ansible-modules-core and ansible-modules-extra respectively.

Q25) How to automate the password input in playbook using encrypted files?

To automate password input we can have a password file for all the passwords of encrypted files will be saved and ansible can make a call to fetch those when required.

ansible_ssh_common_args: ‘-o ProxyCommand=”ssh -W %h:%p -q”‘

This can also be achieved by having a separate script that specifies the passwords. But in this case, we need to print a password to stdout to work without annoying errors.

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

Q26) What are callback plugins in Ansible?

Callback plugins basically control most of the output we see while running cmd programs. But it can also be used to add additional output. For example log_plays callback is used to record playbook events to a log file, and mail callback is used to send email on playbook failures. We can also add custom callback plugins by dropping them into a callback_plugins directory adjacent to play, inside a role, or by putting it in one of the callback directory sources configured in ansible.cfg.

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

There’s a copy module that has a recursive parameter in it but there’s something called synchronize which is more efficient for large numbers of files.

For example:

  • synchronize:
    src: /first/absolute/path
    dest: /second/absolute/path
    delegate_to: “{{ inventory_hostname }}”

Q28) What is the best way to make Content Reusable/ Redistributable?

To make content reusable and redistributable Ansible roles can be used. Ansible roles are basically a level of abstraction to organize playbooks. For example, if we need to execute 10 tasks on 5 systems, writing all of them in the playbook might lead to blunders and confusion. Instead we create 10 roles and call them inside the playbook.

Q29) What are handlers?

Handlers are like special tasks which only run if the Task contains a “notify” directive.


  • name: install nginx apt: pkg=nginx state=installed update_cache=true notify:
    • start nginx
  • name: start nginx
    service: name=nginx state=started

In the above example after installing NGINX we are starting the server using a start nginx handler.

Q30) How does dot notation and array notation of variables are different?

Dot notation works fine unless we stump upon few special cases such as

If the variable contains a dot(.), colon(:), starting or ending with an underscore or any known public attribute. If there’s a collision between methods and attributes of python dictionaries. Array notation also allows for dynamic variable composition.

Q31) What is the code you need to write for accessing a variable name?

Variable names can be built by adding using the following method:

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

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


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

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

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

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

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

Q38) 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 stringsTo 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 }}

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

Q40) What are ad-hoc commands?

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.

Q41) Explain Ansible facts

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.

Q42) What makes ansible different from other tools?

For automation from the start and scratch, Ansible works better than other tools.

For Configuration Management – the life cycle, code, and changes can be done by playbooks, roles, and inventory in Ansible.

Q43) Is Ansible written in Python, explain?

Yes, Ansible is written in Python and the learning curve is very simple and easy. Ansible follows a simple deployment process such as there is no requirement of daemons, servers, and clients. It manages the nodes through the SSH and operates parallel in use.

Q44) Differentiate Ansible and Ansible Galaxy?

Ansible Galaxy is the repository for the ansible roles. And the ansible-galaxy command is used that retrieves roles from Ansible Galaxy and installs them. Ansible is the tool that is used for configuration management using inventory and playbooks.

Q45) Which are the OS Ansible can work upon?

The Ansible server supports the Unix/Linux machines and the client machines support the windows Operating Systems.

Q46) How to get connected to an Ansible server?

Follow the steps given in the question number 7.

  1. Run Ansible command on targets? The ‘command’ module is used for taking the command name and list of space-delimited arguments.
    The provided command will get executed on all the modules.
    To create the command tasks without the space-delimited arguments use the ‘args’ or ‘cmd’ parameters
    For windows targets use the ‘win_command’ module instead.

Q47) How are Ansible and Jenkin associated?

Ansible and Jenkin can be integrated using the following steps,

Create a Jenkins Job and configure the SCM repository using the code in GitHub Then configure the build Roles directory is created in the Jenkins workspace

Create the tomcat role in the Jenkins workspace location with the following command

sudo ansible-galaxy init tomcat – offline Ansible playbook is called after the configuring the Jenkins post-build. Then, call the site.yml file and save the job. Next, call the build job and launch the Tomcat URL to check if the application is installed properly.

Q48. Where are the Ansible playbooks stored? What language is the playbook written in?

The inventory file is the hosts and group of hosts on which the modules, tasks, commands in a playbook operates. The default location for the inventory file is /etc/ansible/hosts. Playbooks are the file where the Ansible code is written. The Playbooks are written in YAML.

Q49. What is YAML and how is used in Ansible?

YAML stands for Yet Another Markup Language, Ansible uses YAML syntax for coding the Ansible Playbooks. It is English like language and is easy to write, read, and understand than other language formats such as JSON and XML.

Q50. Is there an alternative to Ansible? If yes why and what are they?

Yes, there are alternatives to Ansible such as Chef and Puppet. They have some additional features such as Node management, orchestration, code management, and visualization. However, each has its pros and cons. Please read the question#3 for the comparison.

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x