Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Beginner Level Ansible Interview Questions For Freshers
2.1.
1. What is Ansible?
2.2.
2. Explain Configuration management?
2.3.
3. What is the use of Ansible?
2.4.
4. What are the features of Ansible?
2.5.
5. What are the benefits of Ansible?
2.6.
6. What is the Ansible Galaxy?
2.7.
7. What are the requirements of the Ansible server?
2.8.
8. Describe the different parts of Ansible?
2.9.
9. What is Ansible Inventory and its types?
2.10.
10. Is Ansible an open-source tool?
2.11.
11. Name the language in which Ansible is written?
2.12.
12. Distinguish between Ansible Playbooks and Roles.
2.13.
13. What are the changes to Ansible?
2.14.
14. Differentiate between a variable name and an environment variable?
2.15.
15. What are CDs and CIs, and what is Ansible's relationship with them?
2.16.
16. Explain what a “playbook” is?
2.17.
17. What is the Ansible Tower?
2.18.
18. Explain how Ansible works.
2.19.
19. What is the Code difference between JSON and YAML?
2.20.
20. Describe ad hoc commands with an example?
2.21.
21. Differentiate between ansible and chef?
2.22.
22. What is a YAML file, and how do we use it in Ansible?
2.23.
23. How can YAML files be effectively utilized in prominent programming languages like JAVA, Python, and more?
2.24.
24. Where are tags used?
2.25.
25. What protocol does Ansible use to communicate with Linux and Windows?
2.26.
26. Explain Ansible tasks?
2.27.
27. Explain Idempotency?
2.28.
28. What are different strategies used to evaluate Ansible projects?
2.29.
29. How can you upgrade the Ansible reboot module to more than 600 seconds?
2.30.
30. How to use docker modules in Ansible?
2.31.
31. How to install Ansible on the CentOS system?
2.32.
32. Explain a few basic words or concepts in Ansible.
2.33.
33. Define the concept of infrastructure as a Code (IaC).
3.
Intermediate Ansible Interview Questions
3.1.
34. How can a loop be implemented within a template to iterate over a group of hosts in a list?
3.2.
35. How can you achieve the difference of the first host in the group?
3.3.
36. Why use the term '{{}}'? And how can one combine dynamic or dynamic words?
3.4.
37. How do I write a Functional Holder?
3.5.
38. How can you keep confidential data in a playbook?
3.6.
39. What are Ansible Vaults, and why are they used?
3.7.
40. What is the difference between Ansible and Puppet?
3.8.
41. What is the Ansible Tower?
3.9.
42. What features does the Ansible Tower offer?
3.10.
43. How to automate the password input in the playbook using encrypted files? 
3.11.
44. What is "Idempotency"?
3.12.
45. What is the Ansible Galaxy?
3.13.
46. How do you use Ansible to create encrypted files?
3.14.
47. What are the "facts" in the Ansible context?
3.15.
48. What is the ad hoc command?
3.16.
49. Explain the difference between a playbook and a game.
3.17.
50. What protocol does Ansible use to communicate with Linux and Windows?
3.18.
51. What are the requirements of Ansible Server?
3.19.
52. What Is Meant by the Ansible task?
3.20.
53. Explain the keywords or concepts in Ansible?
3.21.
54. What are Ad-hoc commands?
3.22.
55. How can you achieve the flexibility of the first host in the group?
3.23.
56. How can you keep personal data in a playbook?
3.24.
57. What are Ansible Vaults, and why are they used?
3.25.
58. What is the evolutionary nature of the shell in Ansible?
3.26.
59. Who can copy a file repeatedly to the target host?
3.27.
60. How do you set the stage or other dynamic areas of ​​work?
3.28.
61. What are the benefits of Ansible?
4.
Advanced Ansible Interview Questions For Experienced Professionals
4.1.
62. What are tags?
4.2.
63. When we talk about tags, how do you sort tasks?
4.3.
64. What is a handler?
4.4.
65. How do you evaluate Ansible projects?
4.5.
66. How do you improve Ansible?
4.6.
67. When do you use {{}}?
4.7.
68. Explain how to access the variables of the shell environment.
4.8.
69. How do you keep data confidential in a playbook?
4.9.
70. Explain in detail the ad-hoc instructions?
4.10.
71. What unit tests are available in Ansible?
4.11.
72. How does the Ansible synchronize module work?
4.12.
73. Describe Callback_plugin in Ansible?
4.13.
74. How does the Ansible set_fact module differ from vars, vars_file, or include_var?
4.14.
75. When is it unsafe to set mass work arguments from a variable?
4.15.
76. How to configure the jump host to access servers that can not be directly accessed?
4.16.
77. What can Ansible do?
4.17.
78. Please explain what the Ansible Galaxy is?
4.18.
79. Describe the module resources in Ansible?
4.19.
80. Please explain what the Red Hat Ansible is?
4.20.
81. What are the Ansible server requirements?
4.21.
82. How to install Ansible on CentOS?
4.22.
83. How to connect to other devices within Ansible?
4.23.
84. Can you build your modules with Ansible?
4.24.
85. What does Fact in Ansible mean?
4.25.
86. What is ask_pass in Ansible?
4.26.
87. Explain what ask_sudo_pass is?
4.27.
88. Explain what is ask_vault_pass?
4.28.
89. Explain Module utilities in Ansible?
4.29.
90. Explain types of modules in Ansible?
5.
Frequently Asked Questions
5.1.
How do I prepare for Ansible interview?
5.2.
What is Ansible and used for?
5.3.
How many core modules do we have in Ansible?
5.4.
What is the main use case of Ansible?
5.5.
How Ansible is used in DevOps?
5.6.
Is Ansible CI or CD?
5.7.
Why YAML is used in Ansible?
6.
Conclusion
Last Updated: May 25, 2024
Easy

Ansible Interview Questions

Master Power BI using Netflix Data
Speaker
Ashwin Goyal
Product @
18 Jun, 2024 @ 01:30 PM

Introduction

Ansible is a simple open-source IT engine that automates application deployment, intra-service orchestration, cloud rendering, and many other IT tools. Ansible is easy because it does not use any agents or custom security infrastructure. Ansible uses a playbook to describe changing functions. The playbook uses a very simple language, i.e., YAML (a human-readable language measurement language), which is very easy for people to understand, read and write.

If you are preparing for an Ansible interview in the future and are looking for a quick guide before your interview, then you have come to the right place.

This blog consists of Top 90 Ansible Interview Questions and Answers. Let's have a look at them.

ansible interview questions

Most Recommended Topic: Html interview questions

Beginner Level Ansible Interview Questions For Freshers

1. What is Ansible?

Ansible is a configuration management system. Used for setting up and managing infrastructure and applications. Allows users to use and update applications using SSH without installing an agent on the remote system.

2. Explain Configuration management?

Configuration management in Ansible is the practice of defining and maintaining an IT infrastructure using scripts known as Playbooks. Ansible allows you to specify how systems should be configured, including software installations, configuration files, and system updates. Configuration management helps you organize your operations and enhance the security.

3. What is the use of Ansible?

Ansible manages IT infrastructure and delivers software applications to remote nodes. Ansible lets you use the app in multiple nodes with a single command. However, there is a need for some programming knowledge to understand Ansible texts.

4. What are the features of Ansible?

Ansible has the following features:

  • Agentless: Unlike Puppet or Chef, no software or agent controls the nodes
  • Python: Built on Python, which is very easy to read and write and is one of the most vital programming languages.
  • SSH: Ensuring the anonymous network makes it secure and easy to set up
  • Push architecture: The main idea is to push multiple codes to prepare and execute actions on client nodes.
  • Set: This is very easy to set up with a shallow learning curve. It is open-source; hence, anyone can access it.
  • Manage inventory: Machine addresses are stored in a simple text format, and we can add different sources of information to pull the list using plug-ins like OpenStack, Rackspace, etc.

5. What are the benefits of Ansible?

Ansible has many capabilities, which include that:

  • It only requires SSH service running on targeted machines.
  • Python is the only dependency needed, and, fortunately, many programs come pre-installed.
  • It requires minimal resources; therefore, there is a low overhead.
  • It becomes easy to read and understand as these activities can be written in YAML.
  • Unlike other tools, most of which are process, Ansible is declarative, describes the desired condition, and fulfills the requirements necessary to achieve it.

6. What is the Ansible Galaxy?

Ansible can communicate with clients suspended in the command line using the Ansible command. It also allows you to make automatic stops using the Ansible-playbook command. To create a primary index structure, you can use the Ansible-integrated tool, the ansible-galaxy.

7. What are the requirements of the Ansible server?

If you are a Windows user, you need to have a virtual machine where Linux can be installed.

8. Describe the different parts of Ansible?

The following are some parts:

  • Inventory
  • Playbooks
  • It plays
  • Jobs
  • Modules
  • Roles
  • Holders
  • Facts
  • Templates
  • Variable

9. What is Ansible Inventory and its types?

An Ansible inventory is a file or collection of files that specifies the hosts on which Ansible should operate. The inventory files list the IP addresses of the target systems and organize them into groups, which allows you to execute and manage tasks on multiple hosts. There are two main types of Ansible inventory:

  • Static Inventory: This is the traditional form of Ansible inventory. It consists of static and manually maintained files where you define your hosts and groups. It is simple to set up and suitable for smaller environments.
     
  • Dynamic Inventory: Dynamic inventories are generated dynamically using scripts. These scripts query the cloud providers or other data sources to discover and define hosts and groups. Dynamic inventories are especially useful in large and rapidly changing environments.

10. Is Ansible an open-source tool?

Yes, Ansible is an open-source tool because we can rewrite modules. The automated open-source engine provides the source for automated applications as needed.

11. Name the language in which Ansible is written?

Ansible is written in Python and Powershell.

12. Distinguish between Ansible Playbooks and Roles.

The following are the differences between Roles and Playbooks: 

RolesPlaybooks
A set of tasks and additional files to configure the hostsA mapping between roles and hosts

Roles are considered group activities in a single container. We can use the MySQL setup role and postfix setup.

Examples: Web Servers etc.

The playbook points out what is going on there. Sometimes a playbook contains one play, but we can get the number as needed.

 Example: site.yml, web servers.yml, etc.

13. What are the changes to Ansible?

The variables are the same as the variables in another programming language. These are given the amount used to determine playbooks. We can also apply the conditions using variables:

- hosts: your host

vars:

port_Tomcat: 2050

Here, a portable Tomcat port is defined, and the value given to the port number is 2020.

14. Differentiate between a variable name and an environment variable?

  The following are the differences between Variable Name and Environmental Variable: 

Variable NameEnvironment Variable
We need to add a string to create dynamic names.Existing variables are required to achieve environmental variables.
We can define more variable names by adding character units.We should use the Ansible playbook to create variables.
Ipv4 address is used for dynamic variable names.Use [{ansible_env.SOME_VARIABLE_A}} to get remote environmental variables

15. What are CDs and CIs, and what is Ansible's relationship with them?

The CD represents continuous delivery, and the CI represents continuous integration; both ways to develop software.

On CD, engineers are developing software that can be downloaded to production at any time. The CI, on the other hand, contains each engineer that loads a standard set combination (usually daily), which results in multiple daily combinations. Ansible is an ideal CI / CD process tool, which provides stable infrastructure for providing a targeted location and sending a request to it.

Developers automated production

16. Explain what a “playbook” is?

The playbook contains a series of YAML-based files that send commands to remote computers via text. Engineers can optimize all complex areas by transferring text to required systems instead of using individual commands to remotely configure computers from the command line. Playbooks are one of Ansible's strongest retailers and are often referred to as the building blocks of the tool.

17. What is the Ansible Tower?

It is a business-based web-based solution that enhances Ansible access to other IT teams by installing an easy-to-use UI (user interface). Its main function is to serve as the basis for all the organization's default activities, allowing users to monitor the configuration and make quick submissions.

18. Explain how Ansible works.

Ansible is divided into two types of servers: control machines and nodes. Ansible is installed on a control computer, and the control machines manage the nodes via SSH.

The control machine contains a configuration file that replaces the node system. Ansible uses the playbook on the controller to extract modules from node systems. Since Ansible is useless, there is no need for an external company tool to connect nodes.

types of servers

19. What is the Code difference between JSON and YAML?

JSON:

{
 "object": {
"key": "value",
"array": [
  {
    "null_value": null
  },
  {
    "boolean": true
  },
  {
    "integer": 1
  },
  {
    "alias": "aliases are like variables"
  }
]
  }
}

 

YAML:

---
object:
  key: value
  array:
  - null_value:
  - boolean: true
  - integer: 1
  - alias: aliases are like variables

20. Describe ad hoc commands with an example?

Ad hoc commands are simple single-line commands used to perform a specific task. You can think of ad hoc instructions as another way to write playbooks. An ad hoc command example is

Command: ansible host -m netscaler -a "nsc_host=nsc.example.com user=apiuser password=apipass"

21. Differentiate between ansible and chef?

  The following are the differences between Ansible and chef: 

AnsibleChef
It is easy to set upIt is not easy to set up
It is easy to manageIt is not easy to manage
Python is used(YAML)Ruby is used(DSL)
The self support package is about $5000 per yearstandard plans start at $72 anually per code

22. What is a YAML file, and how do we use it in Ansible?

YAML files are like any other formatted text file with a few rules similar to those of JSON or XML. Ansible uses this syntax in playbooks as it is more readable than other formats.

23. How can YAML files be effectively utilized in prominent programming languages like JAVA, Python, and more?

In prominent programming languages like Java and Python, YAML files are commonly used for configuration and data serialization. In Python, libraries like PyYAML allow you to parse and generate YAML files easily. On the other hand, Java has libraries like SnakeYAML for similar purposes. For other programming languages, YAML files can be parsed using external libraries or built-in methods.

24. Where are tags used?

Tags are attributes that set the physical structure, games, functions, and roles. If a comprehensive playbook is needed, it is beneficial to use part of it instead of everything. This is where tags are used.

25. What protocol does Ansible use to communicate with Linux and Windows?

For Linux, the protocol used is SSH.

In Windows, the protocol used is WinRM.

26. Explain Ansible tasks?

A task is a unit of Ansible action. It helps by breaking the policy of setting up small files or code blocks. These blocks can be used to perform the process automatically. For example, installing a software or software update:

Command: Enter <package_name>

Command: update <software_name>

27. Explain Idempotency?

Idempotency is an Ansible feature that ensures that only the necessary changes are possible. One or more tasks can be performed multiple times, but it will not replace anything already fixed or working properly. It can be used in Ansible using the created attribute. For example, if the task is to create a directory on the server, then the directory will only be created if it does not already exist. Idempotency ensures quality assurance for both users and software teams.

28. What are different strategies used to evaluate Ansible projects?

There are three strategies for evaluating Ansible projects:

  • Manual Run: Ensures that the system is in custom mode. Although it is an easy way to test Ansible projects, it increases the risk because the results in the test site may not be the same as in the production area.
     
  • Check mode: Check mode lets you know what modules would have changed if the playbook had been used without testing mode. It lets you check whether the project is behaving the way you want it to. Test mode is similar to simulation and is a less commonly used method in Ansible.
     
  • Asserts: It repeats how the test works in programming languages ​​like Python. It ensures that the system has reached the real state, not as an analogy, which you get in test mode. The vaccine shows that the worker did what he was expected to do.

29. How can you upgrade the Ansible reboot module to more than 600 seconds?

The ansible reboot module can be upgraded for over 600 seconds using the syntax below:

- name: Restart the Linux system

  restart:

    restart_the closing time: 1000

30. How to use docker modules in Ansible?

 Docker modules require a Python Docker SDK installed on the host using Ansible.

With Python 2.7 or Python 3, it can be installed using the following:

$ pip insert docker.

 

With Python 2.6, a version before 2.0 will be required. It can be installed using the following:

$ pip install 'docker-py> = 1.7.0'

31. How to install Ansible on the CentOS system?

It can be done easily in two simple steps:

1: Set up the EPEL Repository

EPEL (Extra Enterprise Linux Packages) is an open-source and free community-based repository project from the Fedora team that provides high-quality Linux distribution software packages which include RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux.

The Ansible package is not available in the default repositories, so we will enable the EPEL repository via the command below:

sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

 

It will download all the required packages that will be required to install Ansible.

2: Install Ansible

Now your EPEL repository has been added, all you have to do now is install Ansible using the command below:

yum insert ansible -y

 

That's all! It is a two-step process that takes just a minute!

If you wish to check out the Ansible version installed in your system, use the command below:

ansible -version

32. Explain a few basic words or concepts in Ansible.

Here are some of the keywords used when responding to Ansible:

  • Control Machine: The Control Machine is responsible for providing managed servers. The machine on which Ansible is installed.
     
  • Inventory: An inventory is a launch file that contains information about the various servers you own.
     
  • Playbook: A code file written in YAML format. The playbook contains tasks that need to be done or spontaneously.
     
  • Task: Each task represents one process that needs to be done, e.g., Enter the library.
     
  • Module: A module is a set of tasks that can be performed. Ansible has 100 built-in modules, but you can also customize them.
     
  • Role: Proper role is a predefined way of organizing playbooks and other files to facilitate sharing and reusing supply components.
     
  • Play: The work done from beginning to end or the making of a playbook is called a game.
     
  • Fact: Fact is a global variable that stores information about a system, such as virtual network connections or operating systems.
     
  • Handlers: Used to activate a service condition, such as restarting or stopping a service.

33. Define the concept of infrastructure as a Code (IaC).

Infrastructure such as Code (IaC) is the process of managing and using data servers, storage systems, system configuration, and network infrastructure.

In traditional configuration management systems, minute-by-minute configuration modifications are required in the hands of system administrators and the IT support team. But with IAC, all configuration information is managed and stored in a standard file system, where the system automatically controls infrastructure changes and deals with system configuration.

Therefore, we do not need much effort as everything is managed and automated following the IAC method. Tools like Ansible can be used to use the IAC method.

Must Read Powershell Interview Questions

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Intermediate Ansible Interview Questions

34. How can a loop be implemented within a template to iterate over a group of hosts in a list?

You can use the “with_items” loop construct to iterate over all the hosts in a group and perform a specified task. Let's see an example playbook.

- name: Perform a task on multiple hosts
 hosts: host_group
 tasks:
   - name: task_name
     //perform a task here
     with_items: "{{ groups[host_group] }}"

 

Using this, you can easily perform any task on multiple hosts.

35. How can you achieve the difference of the first host in the group?

This can be done using the command below:

{{hostvars [groups ['webservers'] [0]] ['ansible_eth0'] ['ipv4'] ['address']}}

In the command above, we get the name of the first machine host in the group of web servers. If you are using a template to do this, use Jinja2' #set,' or you can use set_fact, as shown below:

- set_fact: headnode = {{groups [['webservers'] [0]]}}
- debug: msg = {{hostvars [headnode] .ansible_eth0.ipv4.address}}

36. Why use the term '{{}}'? And how can one combine dynamic or dynamic words?

One basic rule is 'always use {{}} unless:.' Terms always work with Jinja2 to resolve the issue. So, 'when: failed_when:' and 'changed_when:' remain a template, and we should avoid adding {{}}.

In some cases, we must use parentheses; otherwise, distinguishing between unexplained variables and the character unit will be challenging.

37. How do I write a Functional Holder?

Suppose you want to create a handle that restarts the service only if it is already active.

As shown below, holders can "listen" to common topics, and tasks can inform those topics. This functionality makes it much easier to configure multiple handles. It also separates the holders from their names, making it easier to share the handles between playbooks and roles:

- Name: Check to restart
shell: check_is_started.sh
register: result
listen: Restart processes

- Name: Restart in terms of step 2
service: name = service status = restarted
when: result
listen: Restart processes

38. How can you keep confidential data in a playbook?

Suppose you have a function that does not want to display the output or command given when using mode -v (verbose). The following function can be used to perform:

- Name: secret function
shell: / usr / bin / do_something --value = {{secret_value}}
no_log: True

This can store verbose output and hide sensitive information from others who would like to see the result.

The no_log attribute can apply to all games:

- strangers: all
no_log: True

39. What are Ansible Vaults, and why are they used?

Ansible Vault is a feature that lets you keep all your secrets safe. It can encrypt all files, all YAML playbooks, or a few variables. It provides a place where you can not only encrypt sensitive data but also incorporate it into your playbooks.

Vault is used for file-level grading where files are fully encrypted or not encrypted. It uses the same password to write and write files, making Ansible Vault easy to use.

40. What is the difference between Ansible and Puppet?

Management and Editing: In Ansible, the server pushes the configuration on nodes on the other side of the puppet, and the client pulls the configuration from the server. Also, in configuration, the doll has a 30-minute voting agent (default settings) to ensure that all nodes are in the right state. Ansible does not have that feature in the free version.

Availability: Ansible has two backup nodes, and the doll has more than one main node. So they both try to be more accessible. 

41. What is the Ansible Tower?

Ansible Tower is Ansible at a more significant business level, a web-based solution for managing your organization with a straightforward visual interface that provides a dashboard with all the status summaries of all strangers, which allows for quick submissions, and monitors all configurations.

The tower allows you to share SSH data anonymously, record all tasks, manage word lists with graphics and adapt to various cloud providers. 

42. What features does the Ansible Tower offer?

  • Ansible Tower Dashboard - Ansible Tower Dashboard displays everything that happens in your Sensible location, such as hosts, inventory status, recent activity, and more.
  • Real-Time Activity Updates - Since Ansible can automatically create complete infrastructure, you can see real-time updates of tasks, such as games and tasks separated by each machine for success or failure. So, with this, you can see your default status and know what's next in line.
  • Multi-Playbook Workflows - It allows you to combine any number of playbooks, regardless of how you use different inventories, use various details, or run other users.
  • Who Done the Work - As the name suggests, you can quickly know who did the work where and when, and all the automated work is securely entered ansible tower.
  • Scale Capacity With Clusters' help, we can connect multiple Ansible Tower locations in the Ansible Tower collection as collections increase duplication and volume, allowing you to measure Ansible automation across the business.
  • Combined Notifications - This feature allows you to notify a person or team if a task is successful or failed for the entire organization at once or customized according to each job.
  • Customize Tasks - Various functions such as Playbook Run, cloud inventory updates, and resource management updates can be organized within Ansible Tower to work according to need.
  • Manage and Track Inventory - Ansible Tower helps you manage your entire infrastructure by allowing you to quickly deploy a list of public cloud providers such as Amazon Web Services, Microsoft Azure, and more.
  • Self-Help - This Ansible Tower feature lets you launch Playbooks with just one click. It can also let you choose from the available, secure credentials or notify you of variables and monitor resulting usage.
  • REST API & Tower CLI Tool - All features available in Ansible Tower are available through Ansible Tower's REST API, which provides an ideal system management system API. The Ansible Tower's CLI tool is available to start operations.

43. How to automate the password input in the playbook using encrypted files? 

To automate the password input in a playbook, you can use encrypted files like Ansible Vault. You can encrypt the password and store it in a Vault-encrypted file, then use the include_vars module in your playbook to include the encrypted file and decrypt the password. This allows you to securely store and use sensitive information in your playbooks without exposing them in plain text.

44. What is "Idempotency"?

Idempotency is an essential factor that we should know. Prevents unnecessary changes in managed hosts. By default, you can perform one or more tasks on the server as many times as you need, but it will not change anything already fixed and working correctly. To put it bluntly, only additional changes are required and are not yet available. 

45. What is the Ansible Galaxy?

This is a tool integrated with Ansible to create a basic index structure. Galaxy is a website that allows users to discover and share relevant content. To download the roles from the website, you can refer to this link:

$ ansible-galaxy enter username.role_name

46. How do you use Ansible to create encrypted files?

To create an encrypted file, 

use the 'ansible-vault create' command.

$ ansible-vault creates a filename.yaml

Then you will receive a command to create a password, then type it again for confirmation. You will now be able to access a new file, where you can add and edit data.

47. What are the "facts" in the Ansible context?

Recent facts and well-known system variables, found in playbooks, are widely used in the application of conditional contexts. Additionally, they collect ad-hoc system information.

You can find all the facts through this command:

$ ansible all- m setup

48. What is the ad hoc command?

Users start ad hoc commands to start actions on hosts without using a playbook. Think of it as one of the commandments.

49. Explain the difference between a playbook and a game.

A game is a set of tasks that works for hosts managed by one or more. Games contain one or more activities. The playbook contains one or more games.

50. What protocol does Ansible use to communicate with Linux and Windows?

For Linux, the protocol used is SSH.

In Windows, the protocol used is WinRM.

Check this out, Ping command in linux

51. What are the requirements of Ansible Server?

If you are a Windows user, you need to have a virtual machine where Linux should be installed.

Also requires python version 2.6 or higher.

52. What Is Meant by the Ansible task?

Ansible Task allows us to split fragment policy pieces into smaller files. These are code blocks that can be used to perform any process automatically.

53. Explain the keywords or concepts in Ansible?

Some of the keywords most commonly used in Ansible, such as

  • Control Machine: The Control Machine is used to provide servers hosted. This is the machine on which Ansible is installed.
  • Inventory: An inventory is a launch file that contains information about the various servers you own.
  • Playbook: A code file written in YAML format. The playbook contains tasks that need to be done automatically or done.
  • Function: Every task represents one process that needs to be done, e.g., to install a library.
  • Module: A module is a set of tasks that can be performed. Ansible has over 100 built-in modules, and you can create custom ones.
  • Role: Role is a predefined way to organize playbooks and other files to make sharing and reusing parts of a provision easier.
  • Play: Work done from beginning to end or making a playbook is called a game.
  • Fact: Fact is a global variable that stores information about a system, such as virtual network connections or operating systems.
  • Holders: Holders are used to activate a service condition, such as restarting or stopping a service.

54. What are Ad-hoc commands?

Ad-hoc Commands are simple single-line commands used to perform a specific task. You can think of Ad-hoc instructions as another way to write playbooks. An example of an Ad-hoc command, as indicated:

ansible host -m netscaler -a "nsc_host = nsc.example.com user = ansiuser password = antipasti"

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

55. How can you achieve the flexibility of the first host in the group?

Uses the following instructions to achieve a different host for the first host:

{{hostvars [groups ['webservers'] [0]] ['ansible_eth0'] ['ipv4'] ['address']}}

This command accesses the host machine name of the first machine in the webservers group. If you do this with a template, use jinja2' #set', or you can use set_fact.

56. How can you keep personal data in a playbook?

The following command is used to store verbose output but hides sensitive information from others who would like to see the outcome.

- Name: secret function
shell: / user / drum / do_somthing -value = {{secret value}}
no_log: True
Also, the no_log attribute can apply throughout the game.

- strangers: all
no_log: True

57. What are Ansible Vaults, and why are they used?

Ansible Vault is a feature that lets you keep all your secrets safe. It can encrypt all YAML files, playbooks, or just a few exceptions. It provides a place where you can also integrate sensory data into your playbooks.

Vault is used with file-level granularity, in which files are fully encrypted or encrypted. It uses the same encryption for encrypting and decrypting data, making Ansible vault easier to use.

58. What is the evolutionary nature of the shell in Ansible?

In Ansible, if you want to access the available variables, you must use the 'env' test plugin.

For example, you want to access the amount of Office space in the administrator, as shown in the following command, such as:

---
# ...
vars:
local_home: "{{view ('env', 'Office')}}"
I
{{ansible_env.SOME_VARIABLE}}

59. Who can copy a file repeatedly to the target host?

The "copy" module has a recurring parameter. So, if you want to make the most of many files, then the "synchronize" module is the best way to do this job.

60. How do you set the stage or other dynamic areas of ​​work?

Natural variables can be set using the keyword' location'. It can be set for a specific task or a whole playbook. Follow the following code to see how you set it, such:

environment:
HOW: "{{ansible_env.PATH}}: / thingy / bin"
OTHERS: number

61. What are the benefits of Ansible?

  • Ansible has many capabilities, which include that:
  • It only requires SSH service running on targeted machines.
  • Python is the only dependency needed, and, fortunately, many programs come pre-installed.
  • It requires minimal resources; therefore, there is a low overhead.
  • It becomes easy to read and understand as these activities can be written in YAML.
  • Unlike other tools, most of which are process, Ansible is declarative, describes the desired condition, and fulfills the requirements necessary to achieve it.

Must Read WCF Interview Questions

Advanced Ansible Interview Questions For Experienced Professionals

62. What are tags?

A tag is an attribute that can be set in the Ansible format (games, roles, tasks), and then when using a playbook, you can use tags or skip tags to create a small set of tasks.

63. When we talk about tags, how do you sort tasks?

You can filter tasks in one of two ways:

  • Use the tags or skip-tags option in the command line
  • In Portable Configuration settings, use the TAGS_RUN and TAGS_SKIP options.

64. What is a handler?

In Ansible, the handle is similar to the normal function but will only work if the function notifies the holder. Holders are automatically loaded by the roles / <role_name> /handler/main.yaml. The catchers will run once after all tasks have been completed in a particular game.

65. How do you evaluate Ansible projects?

There are three test modes available:

  1. Asserts- It ensures that your system has reached its intended destination, not just as an analogy you can find in test mode.  
  2. Check Mode- Check mode shows you how everything will work if no simulation is done. Therefore, you can easily see that the project behaves as you want. The check mode does not use scripts and commands in paragraphs and playbooks. You must disable the test mode for specific tasks using “check_mode: no.”
  3. Manually Run- Start the game and make sure the system is in the desired condition. This test option is a straightforward method but carries additional risk because the results in the test site may not vary in the production area.

66. How do you improve Ansible?

Improving Ansible is easy. Just use this command: 

sudo pip install ansible == <version-number>

67. When do you use {{}}?

One of Ansible's basic rules states: "Always use {{}} unless:"

68. Explain how to access the variables of the shell environment.

You can access different versions of the control machine by using the "env" check plugin. For example, to achieve the maximum number of home automation controls, you can enter:

local_home: "{{lokup ('env', 'HOME')}}"

69. How do you keep data confidential in a playbook?

If you want to keep your data private but can share it publicly, use Vault in playbooks. But if you are using -v (verbose) mode and do not want anyone to see results, use:

name: secret function
shell: / usr / bin / do_something --value = {{secret_value}}
no_log: True

70. Explain in detail the ad-hoc instructions?

However, ad-hoc commands are nothing but a command used to do something quickly and are to use one time. In contrast, a playbook is used for repetitive action, which is helpful in a logical environment. But there may be situations where we want to use ad-hoc commands that can do the required work and not repeat functions.

71. What unit tests are available in Ansible?

Unit testing of all modules is available in the .test / units/module. First, you have to set your test location.

72. How does the Ansible synchronize module work?

Ansible synchronize is a rsync-like module for Linux machines that we can use in playbooks. Features are like rsync like archive, press, delete, etc., but there are a few limitations.

  • Rsync should be installed on both the source and the target system
  • You need to specify delegate_to to change the source from localhost to another port
  • You need to manage the user's permissions as files are accessible by the remote user.
  • We should always provide a complete home directory when using sudo. Otherwise, the files will be copied to the remote user's home directory.
  • Linux rsync restrictions related to solid links also apply here.
  • Enforcing -description updates to avoid a broken state if the connection does not work.

An example of a sync module is

---
- hosts: host-remote tasks:
- name: sync from sync_folder
synchronize:
src: /var/tmp/sync_folder dest: /var/tmp/

Here we transfer the files to the folder

/ var / tmp / sync_folder to the remote / folder / var / tmp folder.

73. Describe Callback_plugin in Ansible?

 Callbacks are defined as a piece of code in the Ansible environment where to get is used to call a particular event, and notifications are allowed. This is an additional type of developer-related feature and allows for low-level extensions to be able to be loaded from a variety of locations without any problem.

74. How does the Ansible set_fact module differ from vars, vars_file, or include_var?

In Ansible, set_fact is used to set new variable values ​​on a host-by-host basis, similar to the logical realities found in the settings module. These changes are available in the following games in the playbook. In the case of vars, vars_file, or insert_var, we know the value in advance, and if we use set_fact, we can save the agreement after adjusting it over time using certain functions such as applying filters or taking small components of some kind. We can also set up an existing database.

A set_fact variable assignment is done using key-pair values ​​where the key is a variable word, and the value is its function. A simple example will be the same below.

- set_fact:
one_fact: value1
second_fact: value2

75. When is it unsafe to set mass work arguments from a variable?

All work arguments can be dictionaries typed in a dictionary which can be helpful in some dynamic duplication situations. However, Ansible issues a warning as it introduces security risks.

vars:
usermod_args:
name: testuser
state: present
update_password: always
tasks:
- user: '{{ usermod_args }}'

In the example above, the values ​​ that are transferred to the variable usermod_args can be written over other malicious matters ​​in real estate domains on the targeted machine. To avoid this:

The precedence should be greater than the facts of the host.

It would help if you disabled the INJECT_FACTS_AS_VARS configuration to prevent actual and variable price conflicts.

76. How to configure the jump host to access servers that can not be directly accessed?

We should set up ProxyCommand on the ansible_ssh_common_args inventory variable. To connect to the appropriate host, the arguments defined in this variable are added to the scp / ssh / sftp command line.

For example, 

[gatewayed]
foo ansible_host=192.0.2.1
bar ansible_host=192.0.2.2

With the following contents, create the group_vars/gatewayed.yml 

ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q user@gateway.example.com"'

When connecting to any hosts in the group gatewayed, Ansible will append these arguments/issues to the command line.

77. What can Ansible do?

Ansible can do the following for us:

  • Configuration management
  • Application deployment
  • Task automation
  • IT orchestration

78. Please explain what the Ansible Galaxy is?

Ansible Galaxy refers to the Galaxy website where users will be able to share all the roles in CLI (Command Line Interface), where installation, creation, and management of positions take place.

79. Describe the module resources in Ansible?

Ansible offers many different tools that help engineers while developing their modules. Basic.py is a module that provides access to the mainstream library to access and use as a starting point.

80. Please explain what the Red Hat Ansible is?

Ansible and Ansible Tower are at the end of the changing platforms that can offer the following features or functionality:

  • Provision
  • Deploying applications
  • Planning workflow
  • Manage IT applications
  • IT system configuration
  • Networks
  • Apps

All of these activities are discussed by Ansible, where they can help a business solve real-time business problems.

81. What are the Ansible server requirements?

You need to have a Linux virtual machine with Python 2.6 or a higher version.

82. How to install Ansible on CentOS?

Step 1: Update your Control Node

yum update

Step 2: Install the EPEL Repository

yum filed epel-release

Step 3: Install Ansible

yum install Ansible

83. How to connect to other devices within Ansible?

Once, Ansible is installed and the basic setup is complete, a list of names is created.

 This can be basic, and one can begin to evaluate accordingly. To connect to a different device, you must use the "Ping module." This can be used as an easy way to test a connection.

Ansible - m ping all.

84. Can you build your modules with Ansible?

Yes, we can build or have modules within Ansible.

It is an open-source tool that works primarily on Python. If you can edit in Python, you can start creating your modules within a few hours from the start, and you do not need to have the same prior knowledge.

85. What does Fact in Ansible mean?

The word "Facts" is often used in a logical context. They are described in the playbook areas, which show the known and discovered variables of the system. The facts are used to apply conditional practices and obtain ad-hoc information.

You can see all the facts by

$ ansible all- m setup

So if you want to extract only part of the information, you can use the "setup" module, where you will have the option to filter out and just find the truth you need.

86. What is ask_pass in Ansible?

Ask_pass is managed in Ansible Playbook.

This controls whether the ansible-playbook automatically commands the password. Generally, the default behavior is not:

It is always set to ask_pass = True.

If you use SSH keys for authentication purposes, you do not need to change this setting.

87. Explain what ask_sudo_pass is?

Ask_sudo_pass manages Ansible Playbook to reset Sudo's password. Generally, the default behavior is not:

ask_sudo_pass = True

One has to confirm and change this setting when Sudo passwords are enabled most of the time.

88. Explain what is ask_vault_pass?

The ask_vault_pass is an Ansible command-line option used to prompt the user for the password to decrypt Vault-encrypted files. It ensures that sensitive information stored in encrypted files remains secure and requires user input for decryption during playbook execution.

89. Explain Module utilities in Ansible?

Module utilities in Ansible are a collection of tools and functions that provide additional functionality for working with Ansible modules. These utilities include modules for handling file manipulation, string manipulation, system operations, data transformations, and more. They enhance the capabilities of Ansible modules, allowing for more efficient and flexible automation tasks.

90. Explain types of modules in Ansible?

In Ansible, modules are reusable units of code that perform specific tasks on target hosts. They are the building blocks of Ansible playbooks and provide a wide range of functionality to automate tasks.

The following are the types of modules in Ansible:-

  • Core Modules: These are included with Ansible by default and cover many system administration and automation tasks. For example, ansible.builtin.file, ansible.builtin.copy, ansible.builtin.shell, and ansible.builtin.service.
     
  • Community Modules: These modules are contributed by the Ansible community and can be used to extend Ansible's functionality. They cover many use cases, including cloud providers, databases and network devices.
     
  • Custom Modules: You can create custom Ansible modules to flexibly automate specialized tasks that are unique to a specific environment.

Frequently Asked Questions

How do I prepare for Ansible interview?

Prepare by understanding Ansible concepts, practicing common tasks, and being familiar with playbooks, modules, and roles. Review real-world scenarios and Ansible best practices.

What is Ansible and used for?

Ansible is an open-source automation tool used for configuration management, application deployment, task automation, and infrastructure orchestration. It simplifies complex tasks and ensures consistency in IT environments.

How many core modules do we have in Ansible?

Ansible has numerous core modules covering diverse tasks, including system administration, cloud management, network devices, and more. The number of modules continues to expand with updates.

What is the main use case of Ansible?

Ansible is commonly used for automating repetitive tasks in IT infrastructure. Its main use cases include configuration management, application deployment, cloud provisioning, and managing infrastructure as code.

How Ansible is used in DevOps?

Ansible is used in DevOps to automate infrastructure provisioning, configuration management, application deployment, and orchestration. It simplifies complex tasks, ensures consistency across environments, and enhances collaboration between development and operations teams.

Is Ansible CI or CD?

Ansible is primarily a tool for Continuous Delivery (CD) and Continuous Deployment. It automates the deployment process, but it can be integrated into Continuous Integration (CI) pipelines to streamline the overall DevOps workflow.

Why YAML is used in Ansible?

YAML is used in Ansible because it is human-readable, easy to write, and simple to understand. It allows for clear definition of automation tasks, making playbooks and configuration files more maintainable and accessible for both developers and operations teams.

Conclusion

We have extensively discussed the Ansible interview questions with answersthrough this article in detail. After reading about the Ansible interview questions, are you not feeling excited to read/explore more articles on the topic of file systems? Don't worry; Coding Ninjas has you covered.  

Recommended Reading:

To learn more about DSA, competitive coding, and many more knowledgeable topics, please look into the guided paths on Coding Ninjas Studio. Also, you can enroll in our courses 

Live masterclass