Top 40 Ansible Interview Questions and Answers

Safalta Expert Published by: Aryan Rana Updated Mon, 19 Sep 2022 12:41 AM IST

Highlights

A configuration management system is called Ansible. It is utilised to set up and manage applications and infrastructure. Without the need to set up an agent on a remote server, users can deploy and update apps via SSH.

Red Hat's Ansible product includes a variety of functions. The most essential component of any software development cycle today is automation. Ansible assists with maintaining configuration, running playbooks for continuous deployments, automating development systems, setting production environments, and much more. Let's now examine a few Ansible interview questions.  If you are interested in Digital Marketing or Graphic Designing and want to learn these interesting courses then click on the links mentioned Digital Marketing Course and Graphic Designing course

Download these FREE Ebooks:
1. Introduction to Digital Marketing
2. Website Planning and Creation


Top 40 Ansible Interview Questions and Answers


1. Describe Ansible.


A configuration management system is called Ansible. It is utilised to set up and manage applications and infrastructure.

Free Demo Classes

Register here for Free Demo Classes

Please fill the name
Please enter only 10 digit mobile number
Please select course
Please fill the email
Without the need to set up an agent on a remote server, users can deploy and update apps via SSH.



2. What purpose does Ansible serve?


Ansible is used to deploy software applications to distant nodes and manage IT infrastructure. With Ansible, you may distribute an application to numerous nodes with a single command. To understand the Ansible scripts, nevertheless, some programming experience is required.
 

3. What qualities does Ansible possess?


These characteristics of Ansible:

Agentless: The nodes are not managed by software or an agent, unlike Puppet or Chef.
Python: Built on top of the script-writing and learning-friendly Python programming language. It is a reliable programming language.
SSH: Easy to set up and more secure thanks to passwordless network authentication.
Push architecture: The fundamental idea is to push numerous tiny codes to client nodes in order to configure and execute the activity.
Setup: There is a very small learning curve and it is quite simple to set up. Because it is open-source, anyone can use it.
Manage inventory: The addresses of the machines are kept in a straightforward text format, and we may add more sources of accuracy to the list by using plug-ins like OpenStack, Rackspace, etc.
 

4. What benefits does Ansible offer?


Ansible has a variety of advantages, such as:
  • SSH service must be running on the target machines for it to function without an agent.
  • The only prerequisite is Python, which fortunately is pre-installed on the majority of PCs.
  • There is little overhead because it uses few resources.
  • Given that Ansible jobs are written in YAML, they are simple to learn and comprehend.
  • Ansible is declarative, as opposed to other tools, the majority of which are procedural; it specifies the intended state and completes the conditions necessary to accomplish it.


5. Describe Ansible Galaxy.


The Ansible command on the command line allows Ansible to communicate with configured clients. Additionally, you can use the Ansible-playbook command to automate configuration. Use the ansible-galaxy tool that is along with Ansible to build the base directory structure.

Ansible Galaxy: "init azavea" Packer
 

6. What is CI/CD?


The development and deployment processes are streamlined through the usage of continuous integration. Cohesive software has been developed more quickly as a result of this. In order to find integration faults as quickly as possible, each integration is checked using an automated build.

With continuous delivery, your code may always be moved into production after being pushed to a remote repository. In plainer terms, it is a process where software is created such that it may be put into production at any moment.
 

7. How do you define configuration management?


It's a routine that we ought to stick to in order to monitor any system updates that occur over time. This also helps when a significant bug has been introduced into the system as a result of some recent modifications that need to be corrected with the least amount of downtime possible. Configuration management (CM) keeps track of any system upgrades that are required and makes ensuring that the system's current design and build state is current and operational.
 

8. What specifications do Ansible servers need?


In order to install Linux on a virtual computer if you use Windows, you must be a Windows user. Python 2.6 or later is necessary. If these conditions are met, you can move on without difficulty.
 

9. How do Ansible tasks work?


The task is one of Ansible's unit actions. It is beneficial to divide a configuration policy into smaller files or coding segments. A procedure can be automated using these blocks. To update software or install a programme, for instance:

Command: Install

Command: update


10. Describe a couple of the fundamental Ansible terms or concepts.

Some of the fundamental words that are frequently used when working with Ansible include:
  • Controller machine: The controller machine is in charge of provisioning managed servers. It is the computer on which Ansible is set up.
  • Inventory: An inventory is an initialization file that contains information on the various servers you are in charge of.
  • Playbook: This is a YAML-formatted code file. A playbook essentially lists the actions that must be taken or automated.
  • Task: Each task is an individual action that needs to be taken, such as installing a library.
 

11. Describe a couple of the fundamental Ansible terms or concepts.


Some of the fundamental words that are frequently used when working with Ansible include:

Controller machine: The controller machine is in charge of provisioning managed servers. It is the computer on which Ansible is set up.
Inventory: An inventory is an initialization file that contains information on the various servers you are in charge of.
Playbook: This is a YAML-formatted code file. A playbook essentially lists the actions that must be taken or automated.
Task: Each task is an individual action that needs to be taken, such as installing a library.
A module is a group of tasks that can be carried out. Although Ansible comes with hundreds of pre-built modules, you may also write your own.
Playbooks and other files can be arranged into predefined Ansible roles to make it easier to share and reuse certain provisioning components.
Play: A play is the execution of a playbook or a task from beginning to end.
Facts: Facts are global variables that keep track of information about the system, like operating systems or network interfaces.
Handlers: Handlers are used to trigger changes in a service's status, such as stopping or resuming it.
 

12. Describe a playbook.


A playbook consists of a number of YAML-based files that use scripts to deliver commands to other machines. Instead of utilising individual commands to remotely set up computers, developers can configure entire complicated environments by delivering a script to the needed systems. Ansible's playbooks, often known as its building blocks, are one of its main selling factors.
 

13. Where do tags become used?


Ansible's structure, plays, tasks, and roles are set via tags, which are attributes. When a comprehensive playbook is required, running just a portion of it is more beneficial than doing it as a whole. Tags are applied there.
 

14. What protocol do Windows and Linux utilise for communication with Ansible?


SSH is the protocol used by Linux.

WinRM is the protocol used for Windows.

 


15. What do ad hoc commands entail? Give an illustration


Ad hoc commands are short, one-line commands that are used to carry out specific tasks. Ad hoc commands might be viewed as an alternative to playbooks. An illustration of an ad hoc command is the following:

 

the following command: ansible host -m netscaler -a "nsc host=nsc.example.com user=apiuser password=apipass"
 

16. Compare Chef and Ansible

 
Ansible Chef
Easy to set up Not very easy to set up
Easy to manage Management is not easy
The configuration language is YAML (Python) Configuration language is DSL (Ruby)
The self-support package is $5,000 annually.

 

The Premium version costs $14,000 annually for each 100 nodes

The standard plan starts at $72 annually per node. The automation version charges $137 per node annually

17. What exactly is a YAML file and how does Ansible use one?


With a few sets of rules akin to those of JSON or XML, YAML files are similar to any other formatted text file. Because it is easier to read than other forms, Ansible utilises this syntax for playbooks.
 


18. What distinguishes Ansible from Puppet?

 
Ansible Puppet
Easy to set up Comparatively harder to set up
Very easy to manage Not very easy to manage
The configuration language is YAML (Python) Configuration language is DSL (Puppet DSL)
The self-support package is $5,000 annually. The premium version costs $14,000 annually for each 100 nodes Enterprise pricing starts at $120 for every node annually. The premium version costs $19,900 annually for each 100 nodes

19. Describe the process for removing cowsay.


If cowsay is already installed, you can disable it in one of the two ways listed below by running playbooks inside of Ansible:

Remove cowsay
Set the environment variable export value. Ansible Nocows equals 1.

Describe Ansible-doc.

Ansible-doc provides details on the modules that have been installed in Ansible libraries. It generates a brief sample that can be put in a playbook, prints out a list of plug-ins and their concise descriptions, and offers a printout of their documentation strings.
 

20. What kind of code is required to access a variable name?


The command shown below will complete the task:

Host variables "inventory hostname"

Which interface + "ansible"

['ipv4']

the address
Because hostvars is a dictionary of every variable in the namespace, using it is crucial. The inventory hostname field identifies the specific host that the host loop is now scanning.

 

21. What procedure is used to verify the inventory variables set for the host?


The command listed below can be used to accomplish this:

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

22. Describe some Ansible facts


You may think of Ansible facts as a means for Ansible to gather details about a host and store them in variables for quick access. The playbook can use the data that is saved in preset variables. Ansible runs the setup module to produce facts.
 

23. When should playbooks and roles be tested?


Tests can be introduced to playbooks in Ansible either by creating new ones or by editing existing ones. As a result, the majority of testing tasks provide clean hosting each time we utilise them. By employing this testing methodology, we require almost no, if any, code modifications.
 

24. Detailed explanations of Ansible modules


Small pieces of code called "Ansible modules" carry out particular tasks. Numerous jobs can be automated using modules. Ansible modules are standalone scripts or functions that run particular tasks idempotently. The output JSON strings as their return value, while the input varies depending on the module type.

Two categories of modules exist:

The core Ansible team maintains these modules, which are always shipped with Ansible itself. The reported issues are fixed before those in the extras repository. Ansible hosts the Ansible-modules-core repository on GitHub as the source for these modules.
Extra Modules: These modules are maintained by the Ansible community; as a result, they are currently included with Ansible but may be removed in the future. Over time, popular extras modules could be elevated to core modules. Ansible hosts the source code for these modules at Ansible-modules-extras on GitHub.
 

25. What do Ansible callback plug-ins do?


Most of the output we see while running CMD applications is controlled by callback plug-ins. In addition, it can be used to add extra outputs or multiple outputs. For instance, the log plays callback is utilised to log playbook events and the main callback is utilised to email users when a playbook fails.

The callback plugins directory next to the play directory, inside a role, or in one of the callback directory sources specified in ansible.cfg are other places where you can install custom callback plug-ins.
 


26. What do Ansible callback plug-ins do?


Most of the output we see while running CMD applications is controlled by callback plug-ins. In addition, it can be used to add extra outputs or multiple outputs. For instance, the log plays callback is utilised to log playbook events and the main callback is utilised to email users when a playbook fails.

The callback plugins directory next to the play directory, inside a role, or in one of the callback directory sources specified in ansible.cfg are other places where you can install custom callback plug-ins.
 

27.  What are the many forms of Ansible inventory?


The hosts and groups of hosts that the tasks, commands, and modules in a playbook will run on are defined in an Ansible inventory file.

Static and dynamic inventory files are both available in Ansible.
  • Static inventory: A host group's managed hosts are listed in a plain text file using either hostnames or IP addresses as part of a static inventory file. Each line includes a list of the controlled host entries underneath the group name. 
  • Dynamic inventory: Plug-ins are preferred, however, scripts written in Python or another programming language can also create dynamic inventory. Static inventory file configuration will not work in a cloud environment because IP addresses change when a virtual server is stopped and resumed again.
 

28. Ansible vault definition.


Instead of writing sensitive information in plain text in playbooks or roles, Ansible vault is used to store data like passwords. Ansible has the capability to encrypt any structured data file or individual value contained within a YAML file.

The data is encrypted by:

Using the command: ansible-vault encrypt foo.yml, bar.yml, and baz.yml
In order to decrypt the data:

Ansible-vault decrypt foo.yml, bar.yml, and baz.yml
 

29. How can we create a multi-task Ansible handler?


Let's say you want to design a handler that only restarts a service when it is already operational.

Tasks can notify generic topics, as seen below, and handlers can comprehend these topics. Triggering numerous handlers is made considerably simpler by this functionality. Additionally, handlers are separated from their names, making it simpler to transfer them between playbooks and roles.
 

30. How do I create user module encrypted passwords?


We may achieve this by employing a short code:

"msg='mypassword' | password hash('sha512','mysecretsalt')" is the output of the ansible all -i localhost, -m debug, -a command.
The Python Passlib library is another option.

Python -c as a command "through passlib.

Print (sha512 crypt.using(rounds=5000); hash import sha512 crypt; import getpass.

hash(getpass.getpass()))"
 

31. Describe the Ansible idea of blocks.


Tasks can be logically grouped into blocks for in-play error handling. The majority of the settings you may make for a single job can be made at the block level, making it much simpler to define data or directives that are shared by all tasks. This does not imply that the directive has an impact on the block itself, but rather that it is inherited by the tasks included within the block, meaning that it will be applied to the tasks rather than the block.

Tasks can be logically grouped into blocks for in-play error handling. The majority of the settings you may make for a single job can be made at the block level, making it much simpler to define data or directives that are shared by all tasks. This does not imply that the directive has an impact on the block itself, but rather that it is inherited by the tasks included within the block, meaning that it will be applied to the tasks rather than the block.
 

32.  What are the registered variables under Ansible?

 

Registered variables are valid on the host for the remainder of the playbook run, which is the same as the lifetime of facts in Ansible. Effectively registered variables are very similar to facts. While using register with a loop, the data structure placed in the variable during the loop will contain a results attribute, which is a list of all responses from the module.

 

36. By default, the Ansible reboot module waits for how many seconds. Is there any way to increase it?

 

By default, the Ansible reboot module waits 600 seconds. Yes, it is possible to increase Ansible reboot to certain values. The syntax given below can be used for the same:


37. What are the Ansible registered variables?


For the remainder of the playbook run, which corresponds to the lifetime of facts in Ansible, registered variables are valid on the host. Facts and efficiently registered variables are fairly similar. The data structure put into the variable during the loop while using the register will have a results property that is a list of all responses from the module.

38. The Ansible reboot module by default waits for how many seconds. Is there a way to make it
bigger?


The Ansible reboot module waits 600 seconds by default. Yes, Ansible reboot can be raised to a certain level. The following syntax can be used for the same thing:

- name: Reboot a Linux system 
reboot:
reboot_timeout: 1200
 

38. Can you recursively copy files to a destination host? Yes, but how?


Using the copy module, we can copy files recursively to a target host. It features a parameter called recursive that copies files from directories. Another module named synchronise was created expressly for this purpose.

synchronise: delegate to: " inventory hostname " src: /first/absolute/path dest: /second/absolute/path
 

39. Can you keep the playbook's info private?


When using the -v (verbose) mode, the following playbook may be useful if you wish to conceal any task in the playbook:

- Secret name Do something command line: /usr/bin/do something —value=secret value
no log: False
The verbose output and concealment of private information from others are its features.
 

40. Can Ansible implement Docker modules? If so, how might you employ it?


You can use Ansible to implement Docker modules.

Installing docker-py on the host is a requirement for Ansible.

The following command instals "docker-py>=1.7.0"
Docker-compose is also necessary for the docker service module.

The following command instals "docker-compose>=1.7.0"

Free E Books