Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconTop 25 Ansible Interview Questions & Answers [For Freshers & Experienced]

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

Last updated:
27th Aug, 2020
Views
Read Time
12 Mins
share image icon
In this article
Chevron in toc
View All
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.

Check out our free courses to get an edge over the competition. 

Ads of upGrad blog

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.

Explore our Popular Software Engineering Courses

Check out upGrad’s Advanced Certification in Blockchain

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.

Explore Our Software Development Free Courses

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:

  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.

In-Demand Software Development Skills

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:

  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.

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 NameEnvironment Variable
To create variable names, you have to add stringsTo access environment variables, you need already existing variables
By adding strings, you can create several variable namesYou should refer advanced Ansible Playbook to create environment variables
For variable names, use the ipv4 addressFor remote environment variable, use {{ Ansible_envSOME_VARIABLES}}

Q19. Compare Ansible with Chef. 

ParametersAnsibleChef
Installation and Set upNo 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 ManagementIt 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 InventoriesIt 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.
PricingFor 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.

Read our Popular Articles related to Software Development

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?

Ads of upGrad blog

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.

Profile

Rohan Vats

Blog Author
Software Engineering Manager @ upGrad. Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Frequently Asked Questions (FAQs)

1What is YAML and why is it used in Ansible playbook?

YAML is used to write data configuration files in a format that is easy to read and understand. It stands for “Yet Another Mark-Up Language”. Playbooks contain information that tells Ansible what to execute. These are written in YAML. YAML is used in playbooks because it is a data format that is compatible with different frameworks and programming languages and also because it is easier to understand when compared to XML and JSON data formats. Hierarchical and nested formats are effectively represented in YAML. As a playbook is similar to a to-do list, YAML is used in playbooks.

2What is Ansible? Is it a DevOps tool?

Ansible is an open-source system configuration management and application deployment tool whose source code is written in Python. It works on both Windows and Linux operating systems. It deals with the automation of repetitive and laborious tasks and ensures faster and more efficient orchestration and software development. Yes, it is the most preferred DevOps tool because it is fast and reliable. Ansible manages similar servers in one go and the performance is very high. Risk is mitigated, coordination of IT infrastructure is done and the feedback loop is accelerated at a faster rate. Hence, Ansible is used for DevOps.

3What does SSH mean?

SSH stands for Secure Shell or Secure Socket Shell. It secures communication over the network by using cryptographic techniques. It is built on a client-server architecture where the session endpoint is at the clients' end and the session actually runs on the server. It works on the transport layer (layer 4) and the Application layer (layer 7) of the OSI(Open Systems Interconnection) model. It is used for forwarding requests to a port, authenticating the client and server using public-private crypto keypair, and works using tunnel mode in virtual private networks ensuring secure communication over a public network.

Explore Free Courses

Suggested Blogs

Top 7 Node js Project Ideas &#038; Topics
31536
Node.JS is a part of the famous MEAN stack used for web development purposes. An open-sourced server environment, Node is written on JavaScript and he
Read More

by Rohan Vats

05 Mar 2024

How to Rename Column Name in SQL
46894
Introduction We are surrounded by Data. We used to store information on paper in enormous file organizers. But eventually, we have come to store it o
Read More

by Rohan Vats

04 Mar 2024

Android Developer Salary in India in 2024 [For Freshers &#038; Experienced]
901296
Wondering what is the range of Android Developer Salary in India? Software engineering is one of the most sought after courses in India. It is a reno
Read More

by Rohan Vats

04 Mar 2024

7 Top Django Projects on Github [For Beginners &amp; Experienced]
51948
One of the best ways to learn a skill is to use it, and what better way to do this than to work on projects? So in this article, we’re sharing t
Read More

by Rohan Vats

04 Mar 2024

Salesforce Developer Salary in India in 2024 [For Freshers &#038; Experienced]
909100
Wondering what is the range of salesforce salary in India? Businesses thrive because of customers. It does not matter whether the operations are B2B
Read More

by Rohan Vats

04 Mar 2024

15 Must-Know Spring MVC Interview Questions
34710
Spring has become one of the most used Java frameworks for the development of web-applications. All the new Java applications are by default using Spr
Read More

by Arjun Mathur

04 Mar 2024

Front End Developer Salary in India in 2023 [For Freshers &#038; Experienced]
902362
Wondering what is the range of front end developer salary in India? Do you know what front end developers do and the salary they earn? Do you know wh
Read More

by Rohan Vats

04 Mar 2024

Method Overloading in Java [With Examples]
26101
Java is a versatile language that follows the concepts of Object-Oriented Programming. Many features of object-oriented programming make the code modu
Read More

by Rohan Vats

27 Feb 2024

50 Most Asked Javascript Interview Questions &#038; Answers [2024]
4311
Javascript Interview Question and Answers In this article, we have compiled the most frequently asked JavaScript Interview Questions. These questions
Read More

by Kechit Goyal

26 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon