All Courses
Ansible Interview Questions

If you’re looking for Ansible interview questions for experienced or freshmen, you’ve come to the right place. There are many options from many reputable companies around the world. According to the survey, Ansible has a market share of about 4.4%. Therefore, there are still opportunities to advance your career at Ansible Analytics. Listed below are the most common Ansible interview questions and answers that can help you prepare for an Ansible interview. Let’s take a look at them.

1. What is Ansible?

Ansible is an open-source platform that facilitates configuration management, task automation, or application deployment. This is a valuable DevOps tool. Written in Python and uses Red Hat. Finally, it uses SSH to zero downtime to SSH.

2. What is the use of Ansible?

Ansible is used to manage IT infrastructure and deploy software apps to remote nodes. Ansible allows you to deploy your application to many nodes with a single command. However, this requires some programming knowledge to understand Ansible scripts.

3. What are the features of Ansible?

Ansible has the following features:

  • Agentless: Unlike Puppet and Chef, there is no software or agent to manage the node.
  • Python: Built on top of Python, it’s very easy to learn and script. This is one of the robust programming languages ​​
  • SSH: Passwordless network authentication makes it safer and easier to set up
  • Push Architecture: Core Concept pushes some small code and takes action on the client node to configure and run
  • Setup: This is very easy to set up with a very low learning curve. It’s open-source. Therefore, anyone can access it.
  • Inventory Management: Machine addresses are stored in simple text format, and plugins such as OpenStack and Rackspace can be used to add various trusted sources to complete the list.

4. What is Configuration Management?

This is the method you need to follow to keep track of all the updates that flow into your system over a period of time. The technique is also useful in situations where introducing new changes introduces fatal errors into the system. Instead of fixing the error, you can track down and undo the new changes (which caused this error).

5. What is Ansible Galaxy?

Ansible can use Ansible commands from the command line to communicate with configured clients. You can also use the ansible-playbook command to automate the configuration. To create the basic directory structure, you can use a tool bundled with Ansible called ansible-galaxy.

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

By creating software on the CD, developers can release it to production at any time. CI, on the other hand, consists of each developer uploading scheduled integrations on a regular basis (usually daily), resulting in multiple daily integrations. Ansible is an ideal tool for the CI / CD process and provides a stable infrastructure for deploying the target environment and then deploying the application.

7. Explain Ansible architecture?

The Ansible automation engine is a key component of Ansible and interacts directly with configuration management databases, cloud services, and the various users who create playbooks to run them.
The following figure shows the Ansible architecture:

Ansible Interview Questions - Architecture

The components of the Ansible automation engine are:

  • Module: Ansible works effectively by connecting nodes and issuing a script called an “Ansible module”. Helps manage packages, system resources, files, libraries, and more.
  • Inventories: These are a list of nodes or hosts that include databases, servers, IP addresses, and more.
  • API: These are used to exchange public or private cloud services.
  • Plugins: Plugins extend Ansible’s core capabilities. It also provides extensions and options for Ansible’s core features such as data conversion, inventory connectivity, and output logging.
  • Playbook: Describes the tasks you need to perform. You can declare configurations, automate tasks, and more using these simple YAML code files.
  • Host: A host is a node system automated by Ansible on any computer, such as Linux, RedHat, Windows, etc.
  • Networking: Ansible is used to automate multiple networks. service. We use a secure and simple automation framework for IT operations and development.
  • Cloud: A system of remote servers that can store, manage, and process data on behalf of local servers.
  • CMDB: A type of repository that acts as a data warehouse for IT installations.

8. Explain Infrastructure as Code?

Infrastructure as code or IaC is a process that DevOps teams need to follow to manage their infrastructure in a more organized way. You must configure disposable scripts and cloud components through a code repository instead of manually configuring them. In addition, it is recommended that it be kept under source control. This improves speed, consistency, and accountability.

9. State the requirements for the Ansible server.

You need a virtual machine that has Linux installed and is running Python version 2.6 or later.

10. What are Ansible tasks?

The task is a unit action of Ansible. It helps by breaking a configuration policy into smaller files or blocks of code. Using these blocks, you can automate a process. For example, to install a package or update software:

Command: Install <package_name>

Command: update <software_name>

11. Can you create reusable content with Ansible?

Yes, Ansible has a concept of roles that help create reusable content. To create a role, you must follow Ansible’s rules for directory structuring and file naming.

12. What is a YAML file and how do we use it in Ansible?

A YAML or file is like a formatted text file with some ruleset, like JSON or XML. We use this syntax for playbooks because Ansible is more human-readable than any other format.
Here are some examples of JSON and YAML:

 "object": {
"key": "value",
"array": [
    "null_value": null
    "boolean": true
    "integer": 1
    "alias": "aliases are like variables"
 key: value
 - null_value:
 - boolean: true
 - integer: 1
 - alias: aliases are like variables

13. What is a playbook?

The playbook contains a set of YAML-based files that use scripts to send commands to remote computers. Instead of using individual commands to remotely configure the computer from the command line, developers can pass scripts to the required systems to configure the entire complex environment. One of Ansible’s most powerful selling points is its playbooks.

14. What is Ansible Tower?

Using this web-based solution, other IT teams can access Ansible via a user-friendly UI (user interface). Tower’s primary function is to act as a hub for all automation tasks in your organization, allowing users to monitor their configurations and perform rapid deployments.

15. What is the purpose of tags?

Tags are attributes that specify the structure, game, task, and role of Ansible. If you need a large playbook, it makes more sense to run only a part rather than the whole. The site uses tags.

16. How to create an empty file with Ansible?

To create an empty file, Ansible uses a file module. To do this, you need to set two parameters.

  • Path-This location is either a relative path or an absolute path and represents the location where the file is created. The name of the file is also included here.
  • State-This parameter must be set to touch to create a new file.

17. How to set up a jump host to access servers having no direct access?

First, you need to set the ProxyCommand in the ansible_ssh_common_args inventory variable. Because this variable is added to the command line for sftp, scp, and ssh, all the arguments are passed to the associated host(s). For example:

staging1 ansible_host=
staging2 ansible_host=

To create these jump hosts, you need to add a command to ansible_ssh_common_args

ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q"'

That way, if you try to connect to any host in the gateway group, Ansible will add these arguments to the command line.

18. What’s an ad hoc command?

The user initiates an ad hoc command to initiate an action on the host without using the playbook. Think of it as a one-shot command.

19. What are the variables in Ansible?

Variables in Ansible are very similar to variables in other programming languages. Variables in Ansible are assigned values based on the playbook. You can also use conditions around variables. Here is an example:

- hosts: your hosts
port_Tomcat : 8080

Here we have defined a variable called port_Tomcat and assigned it port number 8080. Ansible playbooks can use such variables.

20. Explain how you can disable cowsay?

If you have Cowsay installed, you can disable Cowsay by running a playbook in Ansible using two methods:

  • Uninstall cowsay
  • Set up value for the environment variable

 21. Can we manage Windows Nano Server using Ansible?

No, Ansible cannot manage Windows Nano Server. This is primarily due to a lack of full access to the .Net framework used by internal components and modules.

22. What are callback plugins in Ansible?

The callback plugin basically controls most of the output that you see when you run the cmd program. However, it can also be used to add power. A log_plays callback logs playbook events to file, and an email callback sends an email when a playbook error occurs. You can also add custom callback plugins by placing them in the callback_plugins directory, role, or one of the callback directory sources configured in ansible.cfg next to the play.

23. Explain the difference between a playbook and a play?

In this context, a play refers to a set of tasks performed on one or more managed machines. The play consists of one or more tasks. A playbook consists of one or more plays.

24. Does Ansible support AWS?

Ansible has hundreds of modules that support AWS, some of which include:

  • Autoscaling groups
  • CloudFormation
  • CloudTrail
  • CloudWatch
  • DynamoDB
  • ElastiCache
  • Elastic Cloud Compute (EC2)
  • Identity Access Manager (IAM)
  • Lambda
  • Relational Database Service (RDS)
  • Route53
  • Security Groups
  • Simple Storage Service (S3)
  • Virtual Private Cloud (VPC)

25. What is the method to check the inventory vars defined for the host?

This can be done by using the following command:

ansible -m debug -a "var=hostvars['hostname']" localhost

26. How do you access Shell Environment Variables?

If you just want to access existing variables, you can use the “env” lookup plugin.

For example:

Accessing the values ​​of home environment variables on the management machine:


27. What is Ansible Vault?

Rather than storing passwords as playbooks and roles, the Ansible Vault stores sensitive data as plain text. Individual values ​​in structured data files or YAML files can be encrypted with Ansible.

To encrypt a file

ansible-vault encrypt foo.yml bar.yml baz.yml

And similarly to decrypt

ansible-vault decrypt foo.yml bar.yml baz.yml

28. What’s a handler?

In Ansible, handlers are similar to regular tasks in playbooks, but only when the task notifies the handler. Handlers are automatically loaded from roles/<role_name>/handlers/main.yaml. The handler runs once after completing all the tasks in a particular play.

29. Explain the concept of blocks under Ansible?

Blocking allows for the logical grouping of tasks and in-play error handling. Most of what can be applied to a single task can be applied at the block level. This also makes it much easier to specify common data or instructions for tasks. This does not mean that the directive affects the block itself, but is inherited by the task enclosed in the block. And it applies to the task, not the block itself.

30. When do you use {{ }}?

One of Ansible’s most basic rules is: “Always use {{ }} except when:”