Ansible interview questions and answers for DevOps Engineer | Ansible interview questions and answers
Ansible interview questions and answers for DevOps Engineer
1.What is Ansible?
Answer: Ansible is an open-source automation tool
that allows you to manage and configure systems, deploy applications, and
orchestrate complex IT tasks. It uses a declarative language called YAML to
define configurations and tasks.
2.What is a playbook in Ansible?
Answer: A playbook in Ansible is a file written in
YAML format that defines a set of tasks to be executed on remote systems. It
describes the desired state of the system and Ansible takes care of bringing
the system into that state.
3.How do you install Ansible on a control node?
Answer: Ansible can be installed on a control node
using package managers like apt (for Ubuntu), yum (for CentOS), or pip (Python
package manager). For example, on Ubuntu, you can use sudo apt install ansible
to install it.
4.What is an inventory file in Ansible?
Answer: An inventory file in Ansible is a
configuration file that lists the hosts or groups of hosts that Ansible can
manage. It defines the target systems on which Ansible will run tasks and can
also include variables specific to each host or group.
5.How do you run an Ansible playbook?
Answer: You can run an Ansible playbook using the
ansible-playbook command followed by the playbook filename. For example,
ansible-playbook myplaybook.yml.
6.What is the purpose of Ansible roles?
Answer: Ansible roles are a way to organize and
structure playbooks. They allow you to group related tasks, variables, and
files into reusable components, making playbooks more modular and easier to
manage.
7.How do you handle errors in Ansible?
Answer: Ansible provides a mechanism called
"failed_when" that allows you to handle errors and failures in tasks.
By using conditional statements, you can define specific conditions under which
a task is considered failed.
8.What are Ansible facts?
Answer: Ansible facts are variables that contain
information about the target system. They include details such as the hostname,
IP address, operating system, and hardware specifications. Facts can be
accessed and used in Ansible playbooks.
9.How do you encrypt sensitive data in Ansible playbooks?
Answer: Ansible provides a feature called
"Ansible Vault" for encrypting sensitive data. It allows you to
encrypt and decrypt variables, files, or even entire playbooks using a password
or encryption key.
10.How do you run ad hoc commands in Ansible?
Answer: Ad hoc commands in Ansible allow you to run
simple tasks or execute commands on remote systems without the need for a
playbook. You can use the ansible command followed by the target hosts and the
desired module.
11.What is the difference between Ansible and Ansible
Tower?
Answer: Ansible is the open-source automation tool,
while Ansible Tower is a web-based interface and management tool that provides
additional features like a dashboard, role-based access control, job
scheduling, and REST API.
12.How do you configure a host-specific task in Ansible?
Answer: In Ansible, you can use conditional
statements based on host variables or facts to configure host-specific tasks.
By checking the values of specific variables, you can define tasks that are
only executed on specific hosts.
13.What is the purpose of Ansible Galaxy?
Answer: Ansible Galaxy is a platform for sharing and
discovering reusable Ansible roles. It provides a repository of pre-written
roles that can be easily integrated into your own playbooks.
14.How do you manage secrets and sensitive data in
Ansible?
Answer: Ansible provides various mechanisms for
managing secrets and sensitive data, such as using Ansible Vault, external
credential storage systems, or external key management solutions like HashiCorp
Vault or CyberArk.
15.How do you handle different environments (e.g.,
development, staging, production) in Ansible?
Answer: Ansible allows you to define different
inventory files for each environment. You can then use conditionals and
variables in your playbooks to apply environment-specific configurations and
tasks.
16.What is idempotence in Ansible?
Answer: Idempotence in Ansible means that running a
playbook multiple times should result in the same state. Ansible achieves
idempotence by checking the current state of the system against the desired
state and only making necessary changes.
17.What is the difference between handlers and tasks in
Ansible?
Answer: Tasks in Ansible define the actions to be
performed on the target systems, while handlers are special tasks that are only
run when explicitly called by another task. Handlers are typically used to
restart services or trigger specific actions.
18.How do you perform rolling updates or rolling restarts
using Ansible?
Answer: Rolling updates or rolling restarts in
Ansible can be achieved by using the serial keyword in a playbook. It allows
you to define the number of hosts that should be updated or restarted at a
time.
19.What is the purpose of Ansible facts cache?
Answer: Ansible facts cache is a feature that allows
you to store system facts on the control node. It helps to speed up subsequent
Ansible runs by avoiding the need to gather facts again, especially in large
environments.
20.How do you handle dependencies between tasks in
Ansible?
ConversionConversion EmoticonEmoticon