Top 25 Ansible Interview Questions & Answers [For Freshers & Experienced]

Ansible Interview Questions are the most researched topic on the internet these days owing to the popularity gained by Ansible in recent times. Automation is gaining so much popularity these days in almost every IT process as it reduces the need for manual intervention and the need for more resources, and Ansible helps the industry achieve it.

Ansible makes both automation as well as Configuration Management easy. Ansible is also new in the IT industry and has gained popularity in a very short time. This is because it helps in automating most of the tasks, saving both resources and time. 

Moreover, it is easy to learn and understand. The popularity of Ansible makes more demand for Ansible in the industry. And to fulfill that demand, more people are being hired, having good knowledge of Ansible so that candidates can implement the same in the projects and prove it beneficial for the industry.

Here are the Ansible Interview Questions that you need to prepare for your next interview. The questions are for both fresher as well as experience levels. These Ansible Interview Questions and Answers will definitely help you in cracking your Interview.

If you want to learn Ansible, learn about it on upGrad, a very well-known name among IT professionals. Well-experienced professionals prepare the learning material offered by upGrad.  You can visit the website and get an in-depth knowledge of Ansible.

Must Read: Ansible vs Chef 

Ansible Interview Questions and Answers

Q1. What are the advantages of Ansible?

Ansible has several advantages and strengths that include:

  • It has no agents but needs only SSH service working on the target machines.
  • It does not need many resources. Hence, there is a low overhead.
  • The only dependency of Ansible is Python, which is pre-installed in most of the systems.
  • Ansible is quite easy to understand.

Q2. What is CD/CI in Ansible?

CI and CD are practices followed in software development. CD abbreviates for Continuous Delivery while CI stands for Continuous Integration.

In CD, the software is built and delivered into production while in CI, different developers working on different modules upload the integrations on a daily basis. Ansible is the perfect tool for both CD and CI as it provides a stable infrastructure for setting the required environment and finally deploying the application.

Q3. How does Ansible work?

Ansible gets usually divided into two types of servers called Controlling Machines and Nodes. It is present on the controlling machines, which further connects to different nodes. A playbook gets run by Ansible on controlling machines that execute the Ansible modules with SSH and removes these modules when execution completes. The controlling Machines manage all the nodes; hence no third party tool is required.

Q4. What is an Ansible Playbook?

The playbook is a file where code for Ansible gets written. The Playbook follows the YAML format and is an essential feature of Ansible. The files contained in the Playbook run sequentially. Overall, the Playbook is the building block of Ansible.

Q5. What is Ansible Tower? What are its features?

Ansible Tower is a web-based solution that makes it easily accessible by IT teams. The main function of Ansible is to act as the hub for all automation tasks. The tower can be used for free for up to 10 nodes.

Below are some of the primary features of Ansible tower:

  1. Job Scheduling. 
  2. It helps to schedule the jobs to run later and set options for repetition.
  3. Roll Based Action Control: You can easily set up different roles and provide access to specific roles using Ansible tower.
  4. Fully Documented REST API: Using REST API, you can easily integrate Ansible with your already existing environment.
  5. Portal Mode: Ansible Tower offers an easy to use UI, which is useful for both newbie and experienced users.
  6. Cloud Integration: Ansible Tower has compatibility with most of the Cloud Environments such as Azure, RackSpace, and Amazon EC2.

Q6. What is Idempotency?

Idempotency is an essential feature of Ansible, which ensures only the required changes occur. As an example, any task can be executed multiple times on the server, but it will not change the part, which is already working correctly. It can be implemented in Ansible using the attribute created.

Q7. What is Ansible Galaxy?

Ansible Galaxy is a storehouse of different Ansible roles through which you can share the content securely. It gets done through the Galaxy website, which lets the users find and share the content as per the role access. Ansible-Galaxy is the command that you can use to install the role, create a new role, remove the already existing role, and perform different tasks on the Galaxy website.

Q8. How to create encrypted files using Ansible?

The main command to manage the encrypted content is Ansible-vault. With this command, files can be encrypted and are used to edit, view, and decrypt the data. The new encrypted file is created by using Ansible-vault to create a command by just passing the file name. As an example; to create Hello.yml use below command:

$ Ansible-Vault create Hello.yml

Q9. What is an ask_pass module?

ask_pass is required when password-based authentication is required to connect to the nodes. Simply add—an ask-pass option with Ansible command. When this option is used, Ansible will prompt for a password from the user to connect.

Q10. What are tags?

When there is a large Ansible playbook, and you want to execute a part of it, it is possible using tags. Tags can be used on different structures in Ansible, but the most basic use of tags is with individual tasks. Tags can be applied to multiple tasks. This is done by using the –tags in the command line option. So all the tasks having this tag will get executed.

Q11. Can you filter the tasks with the help of tags?

Yes, the tasks can be filtered using the Ansible tags. This can be done in the following ways:

  1. You can use –tags option or –skip-tags option on the command-line tool.
  2. You can use TAGS_RUN and TAGS_SKIP options in the Ansible configuration settings.

Q12. What’s a handler?

A Handler is a regular playbook task, but the difference is that playbook tasks occur sequentially while a handler is executed when called by some event or a task. Handlers get executed once only once all the tasks in a specific play get completed. As an example, initiating a new service when the configuration setting changes or installation completes.

Read: DevOps Project Ideas 

Q13. How to test Ansible projects?

Below three methods are available to test Ansible projects:

Asserts: Asserts matches how the test works in other languages such as Python. It verifies the system has reached the actual position where the test executes, not as a simulation, which you find in check mode. Asserts displays that the task did what it actually had to do.

Check Mode: The check mode in Ansible allows users to run the playbook without touching anything else. This implies that it will let the user know what the modules would have changed if the playbook was executed without check mode. Check mode is like a simulation only and is the least used option in Ansible.

Get our free ebook!
Computer Vision with Successful Applications in Healthcare, Retail and More
Download Now

Manual Run: It verifies that the system is in the state you would wish for. It is an easy method, but risky because the results might not be as same as in the production environment.

Q14. How to upgrade Ansible?

 Upgrading Ansible is an easy task. You can do it using the below command:

sudo pip install Ansible==<version-number>

Q15. When do you use {{ }}?

This is one of the basic rules of Ansible: “use {{ }} except when:”

Q16. How do you access shell environment variables?

The existing variables of the controlling machine can be accessed by using the “env” lookup plugin. For example; to get the value of the management machine’s home environment variables, you can enter:

Local_home:”{{lookup(‘env’,’HOME’)}}”

Q17. What are the Ansible Server requirements?

You must have a virtual machine where Linux is installed if you use windows. It needs Python 2.6 or above version. If you manage these requirements, then you can continue with it.

Q18. What is the difference between a variable name and an environment variable?

Variable Name Environment Variable
To create variable names, you have to add strings To access environment variables, you need already existing variables
By adding strings, you can create several variable names You should refer advanced Ansible Playbook to create environment variables
For variable names, use the ipv4 address For remote environment variable, use {{ Ansible_envSOME_VARIABLES}}

Q19. Compare Ansible with Chef. 

Parameters Ansible Chef
Installation and Set up No special set up is required for the client machine. The set up is very simple. The server runs on the master machine, and the client agent runs on the client machine. Therefore, the set up is a little tricky.
Configuration Management It uses YAML, which resembles the English language and is easy to understand. It uses Ruby domain-dependent language. Therefore, knowledge of Ruby is a must.
Statics-Dynamic Inventories It uses static and dynamic inventories, e.g., INI file having hosts present in different sections. The user has to register the host on the chef server.
Pricing For basic operations, the amount is $10,000 / year for 100 nodes and $14,000 in a premium package. It is more affordable, and the amount to pay is $137 per node.

Q20. What’s an ad hoc command?

Ad hoc command is a single task and quick command, which is not reusable. It is mainly used with tasks that get performed very rarely. For example, if you want to shut down all your computers in a lab before holidays, then it can be done with a single Ansible ad hoc command. The command gets executed on /usr/bin/Ansible command-line tool. Multiple tasks can be performed using an ad hoc command, such as copy files, reboot servers, manage users, manage packages, etc.

Q21. What is Configuration Management, and how does it help an organization?

Configuration Management is used to handle the updates systematically and maintain its integrity. With configuration management, all the updates made are maintained and tracked in the system and make sure that the system is up to date. Configuration Management helps organizations in the following ways:

  •         It helps to determine what changes are required with the changes in user requirements.
  •         Reverting back to the previous version, in case the updated version is faulty.
  •         It replaces the incorrect component because the user cannot find out this accurately.
  •         It updates an implementation because of changes in the requirements since the previous implementation.

Q22. What are the different components of Ansible? Explain Ansible architecture.

Ansible Automation Engine is the main component of Ansible, which directly communicates with the configuration management database, different cloud services, and users writing playbooks.

Ansible Automation Engine has the below components:

  •  Inventories: It contains the location of all the nodes, databases, and servers.
  •  APIs: Ansible APIs work like other APIs. The Ansible APIs help in commuting different cloud services and private or public services.
  • Modules: The Ansible modules are used for automating the varieties of tasks. These modules help in managing libraries, packages, files, system resources, and more. Ansible has approximately 450 modules, which can automate almost everything in the Ansible environment.
  • Plugins: Ansible plugins help to execute Ansible tasks. Ansible offers around 100 plugins that help in executing the task with ease.
  • Networking: Ansible helps in automating various networks as well as services by creating a Playbook.
  • Playbook: Playbook is the list of tasks that get executed sequentially. They follow the YAML format and are used for the automation of tasks.
  • CMDB: It is a database containing all the installed IT assets and the relationship between them.
  • Cloud: It consists of the remote server hosted online and used to store, manage, and process the data, instead of a local server.

Q23. What is the difference between playbook and play?

A playbook contains one or more plays, and a play contains one or more tasks.

Q24. How can you copy files on the target host recursively?
Files can be copied to the host using the copy module. There is a recursive parameter that copies all the files present in a directory. The synchronize module is also used for this purpose. You simply have to mention the source and destination directories.

Q25. Can we create modules in Ansible?

Yes, the modules can be created in Ansible. Ansible is an open-source tool that works on python language. Anyone who knows coding can create modules in Ansible.

Also Read: Full Stack Developer Interview Questions

Conclusion

These are the must-read Ansible Interview Questions that make you ready for your next interview and get your dream career as Ansible Analyst. Industries are adapting to the new technologies faster because of the increasing competition so they can stay up to date with the market and get ahead in the race. Ansible is one such technology that has gained a lot of attention from IT industries because of its benefits. If you want to learn more about Ansible, full stack development, check out the PG Diploma on Full stack development program from upGrad.

Prepare for a Career of the Future

INDUSTRY TRUSTED LEARNING - INDUSTRY-RECOGNIZED CERTIFICATION.
Apply Now

Leave a comment

Your email address will not be published. Required fields are marked *

×
Become A Full Stack Developer
Download syllabus & learn from a cutting-edge software development course designed by upGrad & IIIT-B.
Download syllabus
By clicking Download syllabus, I authorize upGrad and its representatives to contact me
via SMS / Email / Phone / WhatsApp / any other modes.
I agree to upGrad terms and conditions and our privacy policy.
Download EBook
Download EBook
By clicking Download EBook, you agree to our terms and conditions and our privacy policy.
Get our free ebook!
Computer Vision with Successful Applications in Healthcare, Retail and More
Download Now