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?
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.
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?
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:
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?
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:
All of these activities are dealing with Ansible, where it can help the business to solve real-time business problems.