Ansible Interview Questions

Ansible Interview Questions

A list of frequently asked Ansible Interview Questions and Answers are given below.

1) What is Ansible?

Ansible is an open-source IT engine that automates application deployment, cloud provisioning, intra service orchestration, and other IT tools.

Ansible is very easy to deploy because it does not use any agents or custom security infrastructure on the client-side, and by pushing modules to the clients. These modules are executed locally on the client-side, and the output is pushed back to the Ansible server. It can easily connect to clients using SSH-Keys.


2) What are the uses of Ansible?

  • Ansible is free to use by everyone.
  • Ansible is very consistent and lightweight, and no constraints regarding the operating system or underlying hardware are present.
  • It is very secure due to its agentless capabilities and open SSH security features.
  • Ansible does not need any special system administrator skills to install and use it.
  • Ansible has a smooth learning curve determined by the comprehensive documentation and easy to learn structure and configuration.
  • Its modularity regarding plugins, inventories, modules, and playbooks make Ansible perfect companion orchestrate large environments.

3) What is Ansible Tower?

Ansible Tower is like Ansible at a more enterprise level. It is the web-based solution for managing your organization with an easy user interface that provides a dashboard with all of the state summaries of all the hosts. And allows quick deployments, and monitors all configurations.


4) What is Ansible Galaxy?

Ansible Galaxy is a galaxy website where users can share roles and to a command-line tool for installing, creating, and managing roles.

Ansible Galaxy gives greater visibility to one of Ansible's most exciting features, such as application installation or reusable roles for server configuration. Lots of people share roles in the Ansible Galaxy.


5) What is Ansible Modules?

Ansible modules are discrete units of code which can be used from the command line or in a playbook task.

The modules also referred to as task plugins or library plugins in the Ansible.

Ansible ships with several modules that are called module library, which can be executed directly or remote hosts through the playbook.

Users can also write their modules. These modules can control like services, system resources, files, or packages, etc. and handle executing system commands.


6) How does Ansible work?

Ansible works by connecting to the nodes and pushing out a small program called Ansible modules to them. Then Ansible executed these modules and removed them after finished. The library of the modules can reside on any machine, and there are no daemons, servers, or databases required.

Ansible Interview Questions

The Management Node is the controlling node that controls the entire execution of the playbook. The inventory files provide the list of hosts where the Ansible modules need to be run. The Management Node makes an SSH connection and executes the small modules on the host's machine and install the software.


7) What are the Ansible Server requirements?

  • If you are a windows user, then you required to have a virtual machine in which Linux should be installed.
  • And it requires python 2.6 version or higher.

8) What are the variables in Ansible?

The variable is very similar to using the variables in a programming language. It helps you to assign a value to a variable and use it anywhere in the playbook. You can put the conditions around the value of the variables and use them in the playbook accordingly.


9) What is Ansible Task?

Ansible Task allows us to break up bits of configuration policy into smaller files. These are the block of code which can be used to automate any process.


10) Explain the basic terminologies or concepts in Ansible?

Some basic terms which are commonly used in Ansible, such as:

  • Controller Machine: The Controller machine is used to provisioning the servers, which is managed. This is the machine where Ansible is installed.
  • Inventory: An inventory is an initialization file which has details about the different servers you are managing.
  • Playbook: It is a code file that is written in the YAML format. A playbook contains the tasks that need to be automated or executed.
  • Task: Every task represents a single procedure that needs to be executed, e.g., installs a library.
  • Module: A module is the set of tasks that can be executed. Ansible has 100s of built-in modules, and also you can create custom ones.
  • Role: The role is a pre-defined way for organizing playbooks and other files to facilitate sharing and reusing portions of provisioning.
  • Play: The task executed from start to finish, or the execution of a playbook is called the play.
  • Facts: Facts are global variables which are store details about the system, such as network interfaces or operating system.
  • Handlers: Handlers are used to trigger the status of a service, such as restarting or stopping a service.

11) What are Ad-hoc commands?

Ad-hoc commands are simple one-line commands which are used to perform a certain task. You can think of Ad-hoc commands as an alternative to writing playbooks. An example of an Ad-hoc command, as shown as follows:

The above Ad-hoc command accesses the NetScaler module to disable the server.


12) How would you access a variable of the first host in a group?

Executes the following commands to access a variable of the first host in a group:

This command is accessing the hostname of the first machine in the webservers group. If you are doing this by a template, then use the jinja2 '#set', or you can use set_fact.


13) How to keep secrete data in a playbook?

The following command is used to keep verbose output but hide the sensitive information from others who would like to be able to see the output.

Also, the no_log attribute can apply to an entire play.


14) What are Ansible Vaults, and why are they used?

Ansible Vault is a feature that allows keeping all your secrets safe. It can encrypt entire files, YAML playbooks, or even a few variables. It provides a facility where you also can integrate the sensitive data into your playbooks.

Vault is implemented with file-level granularity, where the files are completely encrypted or unencrypted. It uses the same password for encrypting as well as decrypt the data, which makes Ansible vault user-friendly.


15) What is the way to access shell environment variables in Ansible?

In Ansible, if you want to access existing variables, then you need to use the 'env' lookup plugin.

For example, you want to access the value of the Office environment on the management machine, as shown in the following command, such as:


16) Who you can copy file recursively onto a target host?

The "copy" module has a recursive parameter. Therefore, if you want to perform more efficient for a large number of files, then the "synchronize" module is the best option for doing this task.


17) How do you set the path or any other environment variable for a task?

The environment variables can be set by using the 'environment' keyword. It can be set for either a task or an entire playbook. Follow the following code to see how do set the path, such as:


18) How can you see all variables for a host?

You can see all the variables using the host vary variable. It stores host variables with the hostname as key. For example, to look at the variables defined for localhost, you can run the following command, such as:


19) What is the difference between the Variable Name and Environment Variable in Ansible?

Variable NameEnvironment Variable
You need to add strings to create variable names.You need existing variables to access environment variables.
You can easily create multiple variable names by adding strings.To create environment variables, you must refer to the advanced Ansible playbook.
Use the IPV4 address for variable names.Use {{ansible_env.SOME_VARIABLE}} for remote environment variables.

20) What is RedHat Ansible?

Ansible and Ansible Tower by Red Hat, both are the end to end complete automation platforms which are capable of providing the following features or functionalities:

  1. Provisioning
  2. Deploying applications
  3. Orchestrating workflows
  4. Manage IT systems
  5. Configuration of IT systems
  6. Networks
  7. Applications

All of these activities are dealing with Ansible, where it can help the business to solve real-time business problems.





Latest Courses