Register Login

Top Ansible Interview Questions and Answers

Updated May 15, 2019

What Is Ansible And What Does Ansible Do?

Ansible is an open source tool used for the complete automation of your IT environment. It is used to ease the process of software application deployment, increasing scalability and configuration management of your OS, applications and for implementing security policies.

Explain Architecture Of Ansible?

Ansible architecture is explained below:

  • Modules - The Ansible Modules are small programs that are used to connect nodes. These act as resource models for depicting the state of the system. These are run and deleted when the execution is over.
  • Plugins - These small pieces of code explain the primary Ansible functions.
  • SSH Keys – These are used to operate Ansible. They help in providing access to different modules of users.
  • Inventory – INI files are used to manage all the systems that Ansible is handling. These are placed according to the user’s choice inside the file. Machines can be added without the need of any SSL authentications.
  • Playbooks – These are used to organize the entire architecture of the Ansible system. The number of machines that need to be handled at a time is easily organized with Playbooks.

How Ansible Works?

Ansible works through the following steps:

  • The nodes are connected through Ansible modules. These are executed using SSH.
  • Ansible’s authorized key is used to allows access to different hosts by machines.
  • Additional are added to the inventory without any SSL verifications.
  • Playbooks handle the architectural topology of Ansible.

What Are Ansible Tags?

Tags are used to filter out tasks that need execution without running the entire Playbook. This can be done from the command line.

What Are Ansible Variables?

Ansible variables are used to assign values or conditions to use the playbooks. They can be used to loop over items or may be used for configuration.

What Are Ansible Predefined Variables?

Pre-defined variables are defined by Ansible. Ansible gathers facts about the machines that it operates. These facts can be accessed through playbooks. The syntax for obtaining these variables in the command line is:

ansible -m setup hostname

When Variable Is Defined In Ansible?

Like any programming language, variables are defined when some value needs to be stored. A variable is defined when a certain value has to be used in another system.

What Is Ansible Tower?

Ansible tower is a web-based service that allows all types of IT teams to use it easily for automation. It helps in deploying complicated applications fast and improves productivity. It was very easy to use a central dashboard that allows better administration of the entire IT infrastructure.

What Is Ansible Playbook?

Playbooks are used to organize the entire architecture of the Ansible system. The number of machines that need to be handled is organized with Playbooks. They are a list of tasks that Ansible has to execute. They are written in YAML (Yet Another Markup Language). They run sequentially.

How to Use the Same Playbook For Different Environments?

The same playbook can be used for different environments by the following steps:

  • Create a directory structure including all the necessary folders like main.yml, README.MD.txt, roles, ssh.cfg.
  • Call the roles in the main.yml file.
  • Execute the Ansible playbook.

What Is the Ansible Inventory?

The Ansible inventory contains all the information about the different systems that it handles. It has the hosts on which the modules, tasks and commands in a playbook work. It is located in /etc/ansible/hosts.

How Ansible Is Different From Chef & Puppet?

The differences between Ansible and Chef and Puppet:

  • Ansible is easy to set up whereas Chef & Puppet is not so.
  • The configuration language in Chef is DSL (Ruby), DSL (PuppetDSL) for Puppet, whereas YAML (Python) is used for Ansible.
  • Configuration management is easy in Ansible as it uses YAML. As Ruby DSL is needs programming knowledge, it is difficult. Puppet configuration is tough as it uses its own language called Puppet DSL, where the clint obtains configurations from the server.
  • Ansible is compatible with Windows and LINUX/UNIX machines. Chef runs only on UNIX/LINUX, but its workstation and client are compatible with Puppet Master runs only on UNIX/LINUX, but Puppet Agent works on Windows.

What Is Ansible Inventory?

The Ansible inventory contains all the information about the different systems that it handles. It has the hosts on which the modules, tasks and commands in a playbook work. It is located in /etc/ansible/hosts.

What Is Ansible Register?

The Ansible register variables are used to store the output of a particular task. These variables are applicable to the remote host where the task was executed. The values can be used for configuration and looping.

Where Ansible Hosts File?

The Ansible host files relocated in /etc/ansible/hosts location. A host file contains different host groups and the sub-host groups inside it.

Which Ansible Module Is Used To Manage Docker Services And Containers?

The docker_service module is used to manage Docker Services And Containers.

What Are Ad-Hoc Commands?

Ad-Hoc commands are used to run tasks in the command line against the hosts. It has two parameters, the host group and the module to execute. These tasks can be executed separately.

Give An Example Of Ansible Pre_Tasks.

An example of pre_tasks can be:

pre_tasks:

-name: convert data into uppercase

These are tasks that get executed first.

How To Speed Up With_Items In Ansible? 

To increase the speed of with_items in Ansible, use the raw module instead of the shell module.


×