This article is a collection of some of the most frequently asked Ansible interview questions, which you should prepare in advance of your next interview. Freshers and experienced applicants will benefit from these questions, as they will improve their core skills.
If you're looking for Ansible Interview Questions for Experienced or Freshers, you are at the right place. There are a lot of opportunities from many reputed companies in the world. According to research, Ansible has a market share of about 4.4%. So, You still have the opportunity to move ahead in your career in Ansible Analytics. Mindmajix offers Advanced Ansible Interview Questions 2024 that help you in cracking your interview & acquire your dream career as Ansible Analyst.
Below mentioned are the Top Frequently asked Ansible Interview Questions and Answers that will help you to prepare for the Ansible interview. Let's have a look at them.
We have categorized Ansible Interview Questions - 2024 (Updated) into 3 levels they are
If you're looking to enhance your career and become proficient in Ansible, exploring an "Ansible Training" program could be beneficial. It provides the necessary resources to achieve excellence in this domain. |
Ansible is developed in Python. It is a software tool. It is useful while deploying any application using ssh without any downtime. Using this tool one can manage and configure software applications very easily.
Roles | Playbooks |
Roles are reusable subsets of a play. | Playbooks contain Plays. |
A set of tasks for accomplishing a certain role. | Mapps among hosts and roles. |
Example: common, webservers. | Example: site.yml, fooservers.yml, webservers.yml. |
The main three advantages of using this tool are,i.e. Ansible
Ansible | Puppet |
Simplest Technology | Complex Technology |
Written in YAML language | Written in Ruby language |
Automated workflow for Continuous Delivery | Visualization and reporting |
Agent-less install and deploy | Easy install |
No support for Windows | Support for all major OS’s |
GUI -work under progress | Good GUI |
CLI accepts commands in almost any language | Must learn the Puppet DSL |
There are many similar automation tools available like Puppet, Capistrano, Chef, Salt, Space Walk, etc, but Ansible categorizes into two types of servers: controlling machines and nodes.
The controlling machine, where Ansible is installed and Nodes are managed by this controlling machine over SSH. The location of nodes is specified by the controlling machine through its inventory.
The controlling machine (Ansible) deploys modules to nodes using SSH protocol and these modules are stored temporarily on remote nodes and communicate with the Ansible machine through a JSON connection over the standard output.
Ansible is agent-less, which means no need for any agent installation on remote nodes, so it means there are no background daemons or programs executing for Ansible when it’s not managing any nodes.
Ansible can handle 100’s nodes from a single system over an SSH connection and the entire operation can be handled and executed by one single command ‘ansible’. But, in some cases, where you are required to execute multiple commands for a deployment, here we can build playbooks.
Playbooks are a bunch of commands which can perform multiple tasks and each playbook are in YAML file format.
Ansible can be used in IT Infrastructure to manage and deploy software applications to remote nodes. For example, let’s say you need to deploy a single software or multiple software to 100’s of nodes by a single command, here ansible comes into the picture, with the help of Ansible you can deploy as many applications to many nodes with one single command, but you must have a little programming knowledge for understanding the ansible scripts.
We’ve compiled a series on Ansible, title ‘Preparation for the Deployment of your IT Infrastructure with Ansible IT Automation Tool‘, through parts 1-4 and covers the following topics.
Ansible automation engine is the main component of Ansible, which interacts directly with the configuration management database, cloud services, and various users who write playbooks to execute it.
The below figure depicts the Ansible architecture:
The following are the components of the Ansible Automation engine:
CI/CD is one of the best software development practices to implement and develop code effectively. CI stands for Continuous Integration, and CD stands for continuous delivery. Continuous Integration is a collection of practices that drive developers to implement and check in code to version control repositories. Continuous delivery picks up where continuous Integration ends. This process builds software in such a way that software will be released into production at any given time.
Ansible is an excellent tool for CI/CD processes, which provides a stable infrastructure to a provision target environment and then deploys the application to it.
Yes, Ansible has the concept of roles that helps to create reusable content. To create a role, you need to follow Ansible's conventions of structuring directories and naming files.
Configuration management is the practice to handle updates and manage the consistency of a product's performance over a particular period of time. Ansible is an open-source IT Configuration Management tool, which automates a wide variety of challenges in complex multi-tier IT application environments.
Variable Names | Environment Variables |
By adding strings, we can build variable names | By accessing existing variables, we can access environment variables |
Supports adding more strings | The advanced playbooks section sets the environment variables. |
Use the IPV4 address for variable names. | Use {{ansible_env.SOME_VARIABLE}} for remote environment variables |
To create an empty file, Ansible uses a file module. For this, we need to set up two parameters.
To set the environment variables, we use the environment keyword. We'll use it at the task or other levels in the play:
environment:
PATH: "{{ ansible_env.PATH }}:/thingy/bin"
SOME: value
Obviously, I’d like to be remembered as a master of prose who forever changed the face of literature as we know it, but I’m going to have to settle for being remembered as a science fiction writer (and, more and more, critic) who wrote the occasional funny line and picked up a few awards.
Early imprinting, maybe, for science fiction. When I was quite small a family friend let me read his 1950s run of ‘Galaxy’ magazine. My favorite aunt pressed John Wyndham’s ‘The Day of the Triffids’ on me; a more terrifying great-aunt gave me G.K. Chesterton’s fantastic novels; and so on.
The incurable addiction had begun. Meanwhile, science classes just seemed to be the part of a school that made the most sense, and I fell in love with Pelican pop-maths titles – especially Kasner’s and Newman’s ‘Mathematics and the Imagination’ and all those books of Martin Gardner’s ‘Scientific American’ columns.
This goes back to the 1980s and the Apricot home computers, the early, pretty, and non-PC-compatible ones. My pal Chris Priest and I both used them for word processing, and he persuaded me to put together a disk of utilities to improve the bundled ‘SuperWriter’ w/p, mostly written in Borland Turbo Pascal 3 and later 4: two-column printing, automated book index preparation, cleaning the crap out of the spellcheck dictionary, patching SuperWriter to produce dates in UK format, and so on.
Then I redid the indexing software (‘AnsibleIndex’) in CP/M for the Amstrad PCW and its Locoscript word processors. When the Apricot market collapsed, I wrote an Apricot emulator in assembler so that people could keep using their horrible but familiar old software on a PC. Eventually, in a fit of nostalgia, I collected all my columns for ‘Apricot File’ and various Amstrad PCW magazines as books unoriginally titled ‘The Apricot Files’ and ‘The Limbo Files’. (That’s probably enough self-promotion, but there’s lots more at https://ansible.uk/.)
It appears monthly and has been called the ‘Private Eye’ of science fiction, but isn’t as cruel and doesn’t (I hope) recycle old jokes quite as relentlessly. Though I feel a certain duty to list some bread-and-butter material like conventions, award winners, and deaths in the field, ‘Ansible’ skips the most boring SF news – the long lists of books acquired, books published, book sales figures, major new remainders – in favor of quirkier items and poking fun at SF notables. The most popular departments quote terrible lines from published SF/fantasy and bizarre things said about SF by outsiders (‘As Others See Us’). All the back issues of ‘Ansible’ since it started in 1979 can be read online.
Within the market, they are many automation tools like Puppet, Capistrano, Chef, Salt, Space Walk, etc.
Ansible offers:
No, it is not possible to manage Windows Nano Server using Ansible as it doesn't have full access to the .Net framework, which is primarily used by internal components and modules.
Yes, Ansible Inc makes a great efficient tool. It is easy to use.
Ansible is classified as a web-based solution which makes Ansible very easy to use. It is considered to be or acts like a hub for all of your automation tasks. The tower is free for usage till 10 nodes.
[ Related Article: Learn Ansible Tower Tutorial ]
Features of the Ansible Tower are:
Usually, the documentation is kept in the main project folder in the git repository. Complete instructions on this can be available in docs.
If you are just looking to access the existing variables then you can use the “env” lookup plugin.
For example:
Accessing the value of Home environment variable on the management machine:
local_home:”{{lookup(‘env’,’HOME’)}}”
It is not advised to manage a group of EC2 machines from your laptop. The best way is to connect to a management node inside Ec2 first and then execute Ansible from there.
Yes, it is possible to increase the Ansible reboot module to specific values using the below syntax:
- name: Reboot a Linux system
reboot:
reboot_timeout: 1000
Docker modules require docker-py installed on the host running Ansible.
$ pip install 'docker-py>=1.7.0'
The docker_service module also requires docker-compose
$ pip install 'docker-compose>=1.7.0'
The copy file in Ansible has a recursive parameter. If you have to copy files for a large number of files, then the synchronizing module is the best choice for it.
- synchronize:
src: /first/absolute/path
dest: /second/absolute/path
delegate_to: "{{ inventory_hostname }}"
If cowsay is installed then executing your playbooks within Ansible is very smooth.
Even if you think that you want to work in a professional cow free environment, then you will have two options:
Export ANSIBLE_NOCOWS=1
By default, Ansible gathers facts under machines under management. Further, these facts are accessed in Playbooks and in templates. One of the best ways to view a list of all the facts that are available in a machine, then need to run the setup module in the ad-hoc way:
Ansible- m setup hostname
Once this statement is executed, it will print out a dictionary of all the facts that are available for that particular host. This is the best way to access the list of Ansible_variables.
To see all the host-specific variables, that include all facts and other resources are:
Ansible - m debug- a “var=hostvars[‘hostname’]” localhost
By adding strings together, the variables names are built programmatically like below format:
{{ hostvars[inventory_hostname]['ansible_' + which_interface]['ipv4']['address'] }}
'inventory_hostname' is a variable that represents the present host you are looping over.
We should set a ProxyCommand in the ansible_ssh_common_args inventory variable. For connecting to the relevant host, arguments defined in this variable are added to 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 to the command line.
Ansible ad-hoc command is the easiest option:
ansible all -i localhost, -m debug -a "msg={{ 'mypassword' | password_hash('sha512', 'mysecret') }}"
The mkpasswd utility available on the Linux systems is also the best option:
mkpasswd --method=sha-512
Yes. If any task that you want to keep secret in the playbook when using -v (verbose) mode, the following playbook attribute will be helpful:
- name: secret task
shell: /usr/bin/do_something --value={{ secret_value }}
no_log: True
It hides sensitive information from others and provides the verbose output.
Idempotence is an essential feature of Ansible, which helps you to execute one or more tasks on a server as many times as needed, but without changing the result beyond the initial application.
Yes, using the 'ansible-vault create' command, we can create encrypted files
$ ansible-vault create filename.yaml
A playbook is a list of plays. A play is a set of tasks and roles that run on one or more managed hosts. Play includes one or more tasks.
We can access it through host variables and even works for all the overridden variables like ansible_port, ansible_user, etc.
original_host: "{{ hostvars[inventory_hostname]['ansible_host'] }}"
A tag is an attribute that sets the ansible structure(plays, tasks, roles). When there's an extensive playbook needed, it's more useful to run just a part of it as opposed to the entire thing. That's where tags usage is required.
In Ansible, handlers are just like normal tasks in a playbook but run when tasks include the notify directive and also indicate that it changed something. It runs only once after all the tasks executed in a particular play. It automatically loads through roles/<role_name>/handlers/main.yaml.
They are used to trigger the status of a service, such as restarting or stopping a service.
Using the command "sudo pip install ansible==<version-number>", we can easily upgrade Ansible.
Ansible | Chef |
Ansible is easier to set up and provides faster performance | Compared to Ansible, Chef is not very easy to set up |
Ansible uses YAML (Python) for managing configurations | Chef uses DSL (Ruby) for managing configurations |
Highly scalable | Highly scalable |
Ansible charges annually $10,000 | Chef Automate charges an annual fee of $13700 |
[ Related Article: Ansible vs Chef ]
They are several reasons for not shipping in X format. In general, it caters to maintainability. Within the market, they are tons of different ways to ship software and it is very tedious to support all of them.
Ansible can do the following for us:
Ansible Galaxy refers to the website Galaxy where the users will be able to share all the roles to a CLI ( Command Line Interface) where the installation, creation, and management of roles happen.
Just by setting inventories in the inventory file, we can handle various machines requiring different user accounts or ports to log in.
For example, the following hosts have different ports and usernames:
[webservers]
asdf.example.com ansible_port=5000 ansible_user=alice
jkl.example.com ansible_port=5001 ansible_user=bob
You can specify the connection type to be used by:
[testcluster]
localhost ansible_connection=local
/path/to/chroot1 ansible_connection=chroot
foo.example.com ansible_connection=paramiko
File them in a group_vars/<group-name> file.
Visit here to learn Ansible Training in Bangalore
Ansible is written in Python and PowerShell.
Ansible and Ansible Tower by Red Hat, both are an end to end-complete automation platforms which are capable of providing the following features or functionalities:
All of these activities are dealt with by Ansible which it can help the business to solve real-time business problems.
Yes, Ansible is an open-source tool that is powerful automation software tool that one can use.
Ansible is more a tool for servers but does it have anything for networking? If you closely look into it, there is some support available in the market for networking devices. Using this tool, it will give you an overall view of your environment and also knowledge of how it works when it comes to network automation.
It is one of those tools where it is considered to be good to explore a new tool.
You need to have a virtual machine with Linux installed, which has Python 2.6 version or higher.
Step 1: Update your Control Node
yum update
Step 2: Install the EPEL Repository
yum install epel-release
Step 3: Install Ansible
yum install Ansible
Once, Ansible is installed and the basic setup has been completed, an inventory is created. This would be the base and one can start testing ansible. To connect to a different device then you have to use the “Ping module”. This can be used as a simple connection test.
Ansible - m ping all
Yes, we can create or own modules within Ansible.
It is an open-source tool that primarily works on Python. If you are good at programming in Python you can start creating your own modules in few hours from scratch and you don't need to have any prior knowledge of the same.
After completing the basic setup, one has to make sure to find out the module called the “setup” module. Using this setup module, you will be able to find out a lot of information.
The term “Facts” is commonly used in an Ansible environment. They are described in the playbook areas where it displays known and discovered variables about the system. Facts are used to implement conditional executions and also used for getting ad-hoc information of information.
You can see all the facts via:
$ ansible all- m setup
So if you want to extract only a certain part of the information then you can use the “setup” module where you will have an option to filter out the output and just get hold of the fact that you are in need of.
The ask_pass is controlled in Ansible Playbook.
This controls whether ansible-playbook prompts a password by default. Usually, the default behavior is no:
It is always set to ask_pass=True
If you are using SSH keys for authentication purposes then you really don’t have to change this setting at all.
This control is very similar to ask_pass
The ask_sudo_pass controls the Ansible Playbook to prompt a Sudo password. Usually, the default behavior is no:
ask_sudo_pass= True
One has to make sure and change this setting where the sudo passwords are enabled most of the time.
Using this control we can determine whether Ansible Playbook should prompt a password for the vault password by default. As usual, the default behavior is no
ask_vault_pass= True
Callbacks are explained as a piece of code in ansible environments where to get is used to call a specific event and permit the notifications.
This is more sort of a developer-related feature and allows low-level extensions around ansible so that they can be loaded from different locations without any problem.
Ansible provides a wide variety of module utilities that help developers while developing their own modules. The basic.py is a module that provides the main entry point for accessing the Ansible library and using those as basics one can start off working.
Unit tests for all the modules are available in .test/units/modules. Firstly you have to set up your testing environment
Well, ad-hoc commands are nothing but a command which is used to do something quickly and it is more sort of one-time use. Unlike, the playbook is used for repeated action which is something that is very useful in the Ansible environment. But there might be scenarios where we want to use ad-hoc commands which can simply do the required activity and it is a nonrepetitive activity.
Explore Ansible Sample Resumes! Download & Edit, Get Noticed by Top Employers! |
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Ansible Training | Nov 19 to Dec 04 | View Details |
Ansible Training | Nov 23 to Dec 08 | View Details |
Ansible Training | Nov 26 to Dec 11 | View Details |
Ansible Training | Nov 30 to Dec 15 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.