Important Ansible Interview Questions and Answers For 2021


Ansible is a required skill in many jobs like Lead Architect, AWS Developer, Dev Ops engineer and more. In this article, we are going to list out a few important Ansible interview questions that you should be prepared for before going for the interview, so you have that much-wanted air of confidence about yourself. A quick introduction to Ansible and we shall jump over to the ansible interview questions.


As you might already know, Ansible is a simple open-source IT automation engine that can perform the role of automating cloud provisioning, application deployment, configuration management, intra-service orchestration, and much more. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. It can help you deploy multi-tier IT infrastructure using IaaC (Infrastructure as a Code) written in YAML form describing fluently in plain English like language, how all systems inter-relate.

Ansible is also known for its agentless architecture, reducing the burden of installing and managing these agents across the enterprise. You can only automate cloud provisioning and app deployment; you can create playbooks that can be used to repeat the steps for provisioning and deployment all over again. You can customize Ansible playbooks and reduce the time required for similar infrastructure deployments.

Ansible can help you automate anything under the IT umbrella, infrastructure, applications, networks, containers, security, and cloud. 

Let’s get on with the ansible interview questions.

Basic Concepts based ansible interview questions

  • What is Ansible to you? How have you used it?

Ansible is a simple open-source IT automation engine, that helps you automate cloud provisioning, application deployment, configuration management, and more using Infrastructure as A Code (IaaC) in a simple human-readable YAML form. Ansible was and is primarily used for configuration management to deploy and update applications using SSH across your existing infrastructure. 

  • What are the different uses or different capabilities of Ansible?

Ansible can be used for provisioning cloud infrastructure, configuration management over existing infrastructure, record configuration into repeatable and editable scripts called Ansible Playbooks.

  • What is Ansible Galaxy?

Ansible Galaxy is a public repository of Ansible roles available for quick configuration using playbooks. A role is a set of tasks required to configure a host. Roles are YAML instructions with a predefined directory structure.

  • How is Ansible useful for Continuous Delivery?

Ansible provides multi-tier, multi-step orchestration allowing for a granular control over operations and enabling orchestration of server configuration in batches. Splitting 1000s of servers into manageable groups and updating them a few 100 at a time is easily achieved in Ansible.

  • How to access shell environment variables in Ansible?

To lookup existing environment variables, you need to use the ‘env’ lookup plugin. Here is a simple code

Local_home: “{{lookup(‘env’, ‘office’)}}”

  • How to access a variable name using code?

Variable names can be created using the below command.

{{hostvars[inventory_hostname][‘ansible_’ which_interface][‘ipv4’][‘address’]}}

hostvars is a dictionary of the entire namespace of variables and inventory_hostname specifies the host you are looking up.

  • What is Cowsay and how can you disable it?

Cowsay in Ansible is used to generate ASCII character pictures of a cow with a message and is enabled by default. You could disable it by either changing the environment variable or uninstalling Cowsay.

Set the environment variable with the below code


Advanced Concepts based interview questions

  • How would you copy a file recursively onto a target host?

You can use the copy module with the recursive parameter. If there is a large number of files then the ‘synchronize’ module is the best option to recursively copy a file onto a target host.

  • How is a change in the documentation submitted in Ansible?

Documentation for Ansible is held in a project Git repository and changes can be submitted following simple instructions already documented in the Git repository.

  • How are Ansible configurations in code made reusable or redistributable?

Ansible playbooks are used for reuse and redistribution of a set of repeatable tasks that constitute provisioning or application deployment or any other IT actions executed with limited human involvement.

  • What is Ansible Tower?

Ansible Tower is akin to a security watch tower, that enables you to control access to resources that Ansible was used to deploy.

  • How to check the inventory vars defined for host?

The command that can be used to check the inventory is 

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

  • How to you create encrypted files in Ansible?

By using the ansible-vault create command you can create an encrypted file. The command is as follows.

$ ansible-vault create filename.yaml

The above command will be followed by a prompt to enter a password, followed by a confirmation password.

  • What are ad-hoc commands in Ansible?

Ad-hoc commands are commands that are used to take a specific action or execute a specific task on the hosts and not really part of a sequence of operations. Ad-hoc commands generally would not be reused multiple times in the same context.

  • What are Ansible facts?

After running a setup module on a host, Ansible stores information about the host into variables for easy access in playbooks. These pre-defined variables that give us information about a host system are called Ansible facts.

  • How to check all variables for a host?

All variables of a host are available through the hostvars variable. It is a dictionary of variables, with the name of the variable as the key. Here is an example.

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

  • What are modules in Ansible?

Modules are standalone and reusable scripts that Ansible runs on your behalf, remotely or locally. There are 2 types of modules in Ansible, Core modules, Extras modules.

Core Modules

These are standalone scripts shipped by Ansible along with Ansible software. These are modules that are maintained by Ansible core team.

Extras Modules

These are non-core modules, contributed by the community, but are also shipped along with the Ansible software. Extras Modules are not maintained by the Ansible core team and hence support for the same falls back on the strong Ansible community.

  • What is the difference between playbook and play?

A play is a set of tasks that can be run on one or more hosts, while playbooks are sets of one or more plays.

  • What are tags? How to filter out tags?

A tag is an attribute that you can assign to either a play a role or tasks to be able to select or deselect those tasks, plays or roles when you run a playbook. There are 2 ways to filter out tags, 

Use the –tags or –skip-tags option on the command line.

Disable or enable tags in the Ansible configuration settings using TAGS_RUN and TAGS_SKIP options.


There is no alternative for hands-on experience, so apart from the ansible interview questions that you prepare, it is advised that you get your hands dirty with Ansible, workout a few scenarios yourself before facing the interview.

If you are interested in making a career in the Data Science domain, our 11-month in-person Postgraduate Certificate Diploma in Data Science course can help you immensely in becoming a successful Data Science professional. 


Related Articles

Please wait while your application is being created.
Request Callback