Ansible Interview Questions

Ansible is a configuration management tool which is mainly used for application deployment, task automation, and server configuration which greatly enhances business agility by reducing operational costs, response times, and providing greater benefits to organisations.We have come up with a few Ansible interview questions which will surely help you to be more confident in your interview.

  • 4.5 Rating
  • 19 Question(s)
  • 25 Mins of Read
  • 4955 Reader(s)


Ansible is an open source automation platform that is used for configuration management, application deployment task automation etc. 

It can also do I-T orchestration to run tasks in sequence and create a chain of events which must happen on several different servers or devices. It is developed in Python language. It is useful while deploying any application using ssh without any downtime. 

In simple terms Ansible enables us to define our infrastructure as code(IAC) in a simple declarative manner. 

  • We can easily configure Ansible to run and manage complex processes and functions. 
  •  It is a resource sensitive platform. This means that it optimally utilizes available resources without compromising on the quality of the automated task. 
  •  When Ansible is not managing remote nodes it does not run any background processes. This saves up system memory and does not overwhelm the CPA. 
  •  Most importantly Ansible is powerful reliable and secure as it executes tasks in order and limits the transmission of potentially sensitive data between machines. 
  •  It is easy to set up and configure which is a real advantage when it comes to handling complex processes and large scale deployments with its streamlined efficiency.
  •  It has proven to be a boon for I.T. administrators as it automates to mundane tasks of automation and system upkeep. 
  •  Ansible has a huge engaging online presence in the form of a support community with thousands of experienced members sharing their knowledge and expertise. 
  •  Ansible does not require any dedicated agents to work on it. It only needs open SSH or python on the remote servers. means the ability to manage remote systems without installing additional agents. 
  •  The core idea in Ansible is that we only run and spools automation as needed and we can repeat it without any side effects. 
  •  Ansible is useful in environments where different users have different levels of access. For example, developers, administrators, and QA engineers have managed access to their respective isolated environments. 
  •  There is no accidental risk of a developer pushing content to production.
  •  Ansible is easier to setup than Puppet 
  •  Network Management more easy to using Ansible 
  •  In Terms of scalability, both are highly scalable 
  •  For Ansible 'YAML + Python' and for Puppet 'DSL + PuppetDSL' is used as a configuration language 
  •  Costing of Ansible in production is cheaper than Puppet. 
  •  Ansible is agentless but Puppet needs a customs agent on the remote nodes. 
  •  Ansible is easier to setup than Chef 
  •  Network Management more easy to using Ansible 
  •  In Terms of scalability, both are highly scalable 
  •  For 'Ansible YAML' + Python and for 'DSL + Ruby' is used as a configuration language 
  •  Costing of Ansible in production is cheaper than Puppet. 
  •  Ansible is agentless but Chef needs a customs agent on the remote nodes. 

There are two ways to install it. 

  1.  Using Linux based installation procedure (e.g. using apt or yum) 
  •  For this first add the repository to the APT using command on terminal 'sudo apt-add-repository -y ppa:ansible/ansible' 
  •  Update the repository using command 'sudo apt-get update' 
  •  Now install Ansible using command 'sudo apt-get install -y ansible' 
  1.  Using python installer 
  •  For this first install python on the local machine 
  •  Then using 'sudo pip install ansible' command on terminal install Ansible 
  •  Later on, it can be updated using 'sudo pip install --upgrade ansible' command 

Once Ansible is installed, then verify it with command 'ansible --version' on the terminal. 

  •  Roles are a way to group multiple tasks together into one container to do the automation in a very effective manner with a proper directory structure, they are built on the idea of include files and combine them to form clean, reusable abstractions. 
  •  Roles provide a framework for fully independent or interdependent, collections of variables, tasks, files, templates, and modules. 
  •  Each role is typically limited to a particular theme or desired end result, with all the necessary steps to reach that result either within the role itself or in other roles listed as dependencies. 
  •  Roles themselves are not playbooks. There is no way to directly execute a role. Roles have no setting for which host the role will apply to. Top-level playbooks are the glue that binds the hosts from your inventory to roles that should be applied to those hosts. 

Playbook is a way to send commands to remote computers in a scripted way and has a collection of YAML based files. Instead of using Ansible commands individually to remotely configure computers from the command line, we can configure entire complex environments by passing a script to one or more systems. For example, install and configure something. Basically, a series of resources (e.g. package, copy, file etc) that will achieve our end result in the correct order. 

Knowledge Area: Project Quality Management

Managing the quality of the project deliverables is extremely important. Quality of the deliverables is ensured by doing both Quality Assurance and Quality Control.

Quality Assurance comes from the laid down processes and standards to do the project work. Adherence to the processes and standards assures that the final deliverables will meet the expected standards of quality. This is done proactively through the execution and development.

Quality Control is the process of monitoring the final deliverables and results created by the team after adhering to the chosen processes and standards. Quality Control uses inspection to check if the final deliverable is correct in all respect and meets all the expected specification or not.

For more detailed understanding on the above topic, refer: Qualty assurance and quality control


On the local machine user uses playbook to configure and manage the execution YAML based scripts. Main building blocks of Ansible are playbook, plugins, modules, host inventories, group_vars, roles, handlers, and tags. Using these components we define our configuration and scripts and that is executed on the remote nodes using SSH tunneling. Commands/steps in scripts are executed in order but execution happens in parallel on multiple remote nodes managed by Ansible. Ansible pushes out small program termed as 'modules'; which are responsible for performing all heavy liftings. 

Ansible carries out these modules upon the SSH by default and eliminates them from the remote node machine when finished. 

  •  It is an open source IT configuration management, deployment, and orchestration tool. 
  •  It is unique from other management tools in many respects, aiming to provide large productivity gains to a wide variety of automation challenges as a more productive drop-in replacement for many core capabilities in other automation solutions. 
  •  To solve major unsolved IT challenges such as clear orchestration of complex multi-tier workflows and cleanly unifying OS configuration and application 
  •  Software deployment under a single solution. 
  •  It is designed to be minimal in nature, consistent, secure, and highly reliable, with an extremely low learning curve for administrators, developers, and IT managers. 
  •  To keep descriptions of IT easy to build, and easy to understand - such that new users can be quickly brought into new IT projects, and longstanding automation content is easily understood even after months of being away from a project. 
  •  To make things powerful for expert users, but equally accessible for all skill levels, ensuring a quicker time to market for IT projects and faster, less-error prone turnaround on IT configuration change. 

Workflows are only available with Enterprise-level licenses. Workflows allow configuring a sequence of disparate job templates that may or may not share inventory, playbooks, or permissions. However, workflows have ‘admin’ and ‘execute’ permissions, similar to job templates. A workflow accomplishes the task of tracking the full set of jobs that were part of the release process as a single unit. 

A workflow job can have the following states (no Failed 

  • Waiting
  •  Running 
  •  Success (finished) 
  •  Cancel 
  •  Error 

Ansible Tower is an enterprise framework for controlling, securing and managing Ansible automation with a UI and restful API. 

It provides the following features

  • Real-time Playbook Output and Exploration 
  •  'Push Button' Automation( trigger execution with minimum clicks) 
  •  Enhanced and Simplified Role-Based Access Control and Auditing 
  •  Cloud & Autoscaling Flexibility (allows nodes to request configuration on demand) 
  •  The Ideal RESTful API for a systems management application 
  •  Backup and Restore, replicate Ansible tower instance as needed 
  •  Ansible Galaxy Integration ('Don’t Repeat Yourself', using centralized copies of Ansible roles, such as in Ansible Galaxy and uses of requirements.yml file) 
  •  Inventory Support for OpenStack(This allows to easily target any of the virtual machines or images, which are running in the OpenStack cloud) 
  •  Remote Command Execution 12. Integrated Notifications(allows to easily keep track of the status of your automation using e.g. Slack, E-mail, SMS etc) 
  •  Red Hat Satellite 6 and Red Hat CloudForms Integration 
  •  Run-time Job Customization (Bringing the flexibility of the command line to Tower)  

Ansible playbook files can be reused in multiple ways. Imports and Include are helpful to create/break up multiple small files of a massive playbook. Roles are primarily used to manage various tasks in a package including handlers, variables, plug-in and other modules. They can also be uploaded and shared by Ansible Galaxy. Ansible Tower automatically fetches the roles that playbook needs from Galaxy, GitHub, or your local source control. 

Ansible works by connecting to the remote nodes over SSH and pushing out small programs, called 'modules' to them. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules and removes them when finished. 

Ansible ships with a number of readymade modules (called the 'module library') that can be executed directly on remote hosts or through Playbooks. Users can also write their own modules. These modules can control system resources, like services, packages, or files (anything really), or handle executing system commands. 

Whenever we run an Ansible playbook, Ansible first gathers information ('facts' an exhaustive list of all the environment details) about each host in the play. Facts can be extremely helpful when we’re running playbooks; we can use gathered information like host IP addresses, CPU type, disk space, operating system information, and network interface information to change when certain tasks are run or to change certain information used in configuration files. 

To get a list of every gathered fact available, we can use 'ansible munin -m setup' command with the setup module. 

  •  Handlers are just like regular tasks in a playbook, but they will only be run if a task notifies the handler. If a task that would’ve notified the handlers is skipped due to a when condition or something of the like, the handler will not be run. 
  •  Handlers are automatically loaded from roles/<role_name>/handlers/main.yaml. These handlers can be referenced by any task within the role, or by any tasks within any other role that lists this role as a dependency. 
  •  Handlers will run once, and only once, after all of the tasks complete in a particular play. 
  •  If the play fails on a particular host (or all hosts) before handlers are notified, the handlers will never be run(but we can use the command line flag --force-handlers when running the playbook to run the handler always) 
  •  At a basic level, a task is a way to call an Ansible module. In playbook goal of a play is to map a group of hosts to some well-defined roles, represented by things Ansible calls tasks. 
  •  The task file is the main part of a role. If roles/<role_name>/tasks/main.yaml exists, all the tasks therein and any other files it includes will be embedded in the play and executed. 

There are two types of variables that can be defined in a role:

  1. Role variables: loaded from roles/<role_name>/vars/main.yaml 
  2. Role defaults: which are loaded from roles/<role_name>/defaults/main.yaml 
  •  The difference between 'variables' and 'defaults' is the precedence order. 
  •  Role defaults are the lowest order variables. Any other definition of a variable will take precedence over a role default. 
  •  Role defaults can be thought of as placeholders for actual data, a reference of what variables a developer may be 
  •  interested in defining with site-specific values. 
  •  Role variables, on the other hand, have a higher order of precedence. Role variables can be overridden, but generally, they are used when the same data set is referenced more than once within a role. If the data set is to be redefined with site-local values, then the variable should be listed in the role defaults rather than the role variables. 
  •  If we have a large playbook, it may become useful to be able to run only a specific part of it rather than running everything in the whole Ansible playbook, Ansible supports a 'tags:' attribute for this. 
  •  When we execute a playbook, we can filter tasks based on 'tags' in two ways: 
  •  On the command line, with the --tags or --skip-tags options 
  •  In Ansible configuration settings, with the TAGS_RUN and TAGS_SKIP options 
  •  We can apply the same tag to more than one task and do task inheritance as well. 


Ansible is a configuration management tool which is mainly used for application deployment, task automation, and server configuration which greatly enhances business agility by reducing operational costs, response times, and providing greater benefits to organisations. It is a very popular tool which is fairly easy to use and helps in IT orchestration and can handle complex tasks.

We have come up with a few Ansible interview questions which will surely help you to be more confident in your interview. The following interview questions on Ansible have been designed by experts and intends to give you a glimpse of the interview questions which you might face while you appear for your Ansible interview: