Top 25 Ansible Interview Questions & Answers [For Freshers & Experienced]
Updated on Nov 14, 2022 | 12 min read | 8.3k views
Share:
For working professionals
For fresh graduates
More
Updated on Nov 14, 2022 | 12 min read | 8.3k views
Share:
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.
Check out our free courses to get an edge over the competition.
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.
Check out upGrad’s Advanced Certification in Blockchain
Must Read: Ansible vs Chef
Q1. What are the advantages of Ansible?
Ansible has several advantages and strengths that include:
Check out upGrad’s Advanced Certification in Cloud Computing
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:
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.
upGrad’s Exclusive Software Development Webinar for you –
SAAS Business – What is So Different?
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:
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.
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:
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:
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
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.
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources