Network Kings

Top Most-Asked Ansible Interview Questions and Answers

ansible interview questions

Ansible is a powerful configuration management tool used by IT professionals worldwide. It is used to manage both small and large deployments with ease. Ansible is simple, agentless, and easy to use, making it the perfect tool for DevOps and system administrator tasks. If you are looking for a job that uses Ansible, you will likely be asked to answer Ansible interview questions. In this article, we will share with you the 16 most commonly asked Ansible interview questions with answers. These questions are divided into two categories – Ansible interview questions for beginners and Ansible interview questions for experienced professionals.

No matter your level of expertise, these Ansible interview questions will help you prepare for your next job interview.

Let’s begin with the most commonly asked Ansible interview questions and answers! 

Ansible Interview Questions and Answers for Beginners

1. What is Ansible?

Ansible is an open-source automation platform. It is used to automate IT tasks such as software provisioning, configuration management, application deployment, and ad-hoc task execution. With Ansible, you can manage a large number of hosts with a single command line, manage and connect to multiple servers simultaneously, and automate your infrastructure easily and reliably. 

Ansible comes with a wide range of built-in modules and integration support for popular IT Tools like AWS, Microsoft Azure and more. It is a simple, straightforward and highly efficient tool that helps you set up and manage your IT environment in a repeatable, reliable manner.

2. What is CI/CD and how is Ansible Related to It?

  • Continuous Integration (CI):

The full form of CI is continuous integration. It is used for efficiently running the development and deployment processes. This in return, leads to the formation of more reliable and cohesive software.

In CI, a developer develops software integrations that are uploaded almost daily at a scheduled time which results in multiple integrations every day.

  •  Continuous Delivery (CD):

CD, on the other hand, is known as Continuous Delivery (CI). It is a software development practice where code developed by a software developer is kept in a remote repository. This code can be taken to production at any time.

What is CI/CD and how is Ansible Related to It?

Ansible is a wonderful tool for CI/CD processes as it can provide a stable infrastructure for the target environment in order to carry out a smooth deployment process.

3. How Ansible works?

Ansible is a new-age automation tool. It consists of various chucks working together, which are mainly playbooks, modules, and plugins.

  • Playbooks referred to all the steps that are needed to complete a process. It defines the complete workflow and consists of plays which are small tasks. It is in a YAML file format.
  • Modules refer to small codes that get executed in a task. It acts as a starting point for making the tasks.
  • Plugins run on a main control machine for logging functions. These are special kinds of modules. 
How Ansible works?

There are two main types of servers in Ansible:

  • Controlling machines
  • Nodes

Controlling machines:

  • Ansible is installed in the controlling machines.
  • The controlling machine uses SSH protocols to deploy modules to nodes.

Nodes:

  • The nodes store modules in them for a temporary period of time.
  • It builds a JSON connection in order to communicate with the Ansible machine over the standard output.
  • These nodes are not managed by Ansible when there is no execution of a program or daemon since Ansible is an agent-less tool.
  • Hundreds of nodes can be handled by Ansible from a single system over an SSH connection.

4. Explain the architecture of Ansible.

The most important component of Ansible is the Ansible Automation engine or the Ansible Orchestration engine. It interacts with the user who is writing the Ansible playbook as well as the configuration management database in order to implement the Ansible orchestration.

Here is what the architecture of Ansible looks like:

ansible architecture

Here are all the components of the ansible automation engine in detail:

  • Inventory:

It is a list of nodes or hosts that consists of databases, IP addresses, servers, etc. that are needed to be managed.

  • APIs:

These are used for hosting and transporting public and private cloud services.

  • Modules:

Modules work in an optimal manner by connecting nodes and taking out scripts called ‘Ansible modules’. It manages files, system resources, libraries, etc. These modules can be installed on any machine.

  • Plugins:

Plugins alter the core functionality of Ansible. You can also write your own. 

  • Playbook:

It tells about all the tasks that need to be executed. These tasks are written in YAML format which explains the tasks and executes them through Ansible.

  • Hosts:

These are node systems that are automated by Ansible. These can also be automated by RedHat, Windows, Linux, etc.

  • Networking:

Ansible is agentless and it uses a simple and secure automation framework for IT operations and development. 

  • Cloud:

It is a network of remote servers which can store, manage and process data. These servers store data on a remote network without the use of a local server. 

  • CMDB:

It is referred to as Configuration Management Database (CMDB). It acts as a data warehouse for IT installations. 

5. What is meant by Ad Hoc commands? Quote an example.

These are simple one-line commands used to perform a specific task. These can be performed as individual tasks to run quick functions. They are an alternative to writing playbooks by a user. 

An example of an ad hoc command is given below as follows:

In order to delete a whole directory or file, this command can be run:

$ Ansible abc -m file -a “dest = /path/user1/new state = absent”

6. What is an Ansible task?

When you want to break configuration policies into smaller files, Ansible tasks are the perfect tool to do so. They can automate any process. Please note that these are simply a piece of code.

7. What is the difference between Ansible and Puppet?

Ansible

Puppet

Ansible is easy to set up.

Puppet is comparatively difficult to set up.

It is highly available.

It is highly available as well.

It is very easy to manage. It is less secure.

It is not easy to manage. It is less secure.

It has been made in Python. The configuration language is YAML.

The configuration language in Puppet is DSL (Puppet DSL).

It is more scalable.

It is less scalable as compared to Ansible.

The GUI of Ansible is not very interactive.

Its GUI is more interactive and very developed.

The self-support package costs around $5,000 for a year.

It costs $120 for every node in an enterprise.

8. How to keep secret data in a playbook?

Sometimes we have a task and we do not want to show the output or command that is run while using verbose mode or v-mode, we can then use the following code:

– name: secret task

shell: /usr/bin_a/do_something –value={{ secret_value01 }}

no_log: True

It can be used to keep verbose output

– hosts: all

no_log: True

9. What is meant by Ansible Galaxy?

It is a galaxy website. The users can share roles and they can even share roles with a command-line tool for installing, building, and managing roles.

You can access the best of the best Ansible features by using the Ansible galaxy. These features include:

  • Installing applications.
  • Server configuration.

Many people can share roles in Ansible Galaxy.

10. Can Ansible support AWS?

Ansible has many modules that can support AWS, such as:

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

Ansible Interview Questions with Answers for Experienced Professionals

11. Explain modules in Ansible in detail.

Modules are referred to small pieces of code that perform a certain task in Ansible. They can automate a lot of tasks. When these commands run, they return values in JSON script. The input, however, depends on the type of module.

Modules are of two types:

  • Core modules:
  • These modules are special modules in Ansible that are maintained by the core Ansible team. 
  • They are always shipped with Ansible itself. 
  • If any issue occurs, they are fixed on a priority basis as compared to issues present in the extras repo. 
  • These modules are hosted by Ansible in GitHub. 
  • The Ansible-Modules-Core handles these in GitHub.
  • Extras Module:
  • These modules are special modules that are looked after and maintained by the Ansible community.
  • These are shipped with Ansible. These might be stopped in the future.
  • It is also believed that the most used and popular extras modules will be shifted to core modules in some time.
  • These are hosted by Ansible on GitHub.
  • On GitHub, these are present in the Ansible-Modules-Extras.

12. What is meant by Ansible Inventory? What are its types?

It is a file that is used to define hosts as well as groups of hosts. It contains all the commands, tasks and modules upon which these will be operated in a playbook.

There are two types of inventory files:

  • Static Inventory:

It is a list of managed hosts. It is present under a host group using either hostnames or IP addresses in a plain text file. The host names are enclosed in square brackets ([group name]). The managed host entries are then listed below the group name in their own line.

This is how hosts are listed using either hostnames or IP addresses:

[group name]

Host A ip_address

Host B ip_address

Host c ip_address

  • Dynamic inventory:

It is created by a script that is written in Python or any other programming language such as JavaScript or PHP using plug-ins. The inventory keeps on changing constantly as you add or remove servers in a cloud setup such as AWS. Therefore, dynamic inventory is of best use in a cloud environment where IP addresses change once a virtual server is stopped and started again.

The benefits of dynamic inventory are as follows:

  • They are perfect as they reduce human error because the information is collected using scripts.
  • There is little effort needed to manage inventories.

You can extract information about hosts in a dynamic inventory script by running the following code:

#  ./script — list

13. What are the variables in Ansible?

You can use a single command to execute tasks and playbooks on multiple different systems. These variables in ansible can be to manage differences between these systems. These variables can be created with standard YAML syntax, including lists and dictionaries.

Therefore, these variables in Ansible playbooks are very similar to the variables in a programming language such as Python. 

Here are some of the key features of variables in Ansible:

  • It allows you to use and assign a value to a variable. 
  • You can use it anywhere in the playbook. 
  • You must note that once you apply conditions around the value of the variables and then you can use them accordingly.
  • A variable name can only include numbers, letters and underscores. 
  • Playbook keywords and Python keywords are not valid variable names. 
  • It cannot begin with a number.

Some of the valid variable names are foo, foo_env, foo-port, foo5, and _foo.

The different types of variables in Ansible are:

  • Boolean variables
  • List variables
  • Dictionary variables

Example of a variable is as follows:

– hosts : <your hosts>

vars:

tomcat_port : 8080

14. How to upgrade Ansible?

You can easily upgrade ansible by using a single command:

Sudo pip install ansible ==<version-number>

15. How can you access shell environment variables?

You can create existing variables in the controlling machine by using the “env” lookup plugin. For example, you can enter the following command to access the value of the management machine’s home environment variable:

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

16. How can you create an encrypted file in Ansible?

In order to create an encrypted file in Ansible, you can use the ‘ansible-vault create’ command and pass the filename.

$ ansible-vault create filename.yaml

Then, you will be asked to create a password. You can confirm it by retyping.

After your password is confirmed, a new file will be created. It will get opened in an editing window. The editor for Ansible Vault is vi by default. You can add data here or you can save and exit.

This is how you can create an encrypted file.

Conclusion

Ansible is an invaluable tool for managing IT environments and deployments. As a result, being familiar with the tool and being able to answer Ansible interview questions successfully is integral for landing a job in IT

By reviewing the top most common Ansible interview questions, along with the provided answers, you can get a better sense of what to expect during your next interview and increase your chances of success. 

Good luck!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.