Top 50 Ansible Interview Question.
Here are the answers to the top 50 Ansible interview questions:
What is Ansible?
- Ansible is an open-source automation tool used for configuration management, application deployment, and task automation.
What are the advantages of using Ansible?
- Simple to set up and use
- Agentless architecture
- Idempotent operations
- Strong community support
How does Ansible work?
- Ansible uses SSH for communication and YAML for configuration. It executes tasks on remote systems using modules.
What is an Ansible playbook?
- A playbook is a YAML file containing a series of tasks to be executed on remote hosts.
What is an inventory file in Ansible?
- An inventory file lists the hosts and groups of hosts on which Ansible commands, modules, and playbooks operate.
Explain the architecture of Ansible.
- Ansible architecture includes modules, plugins, inventories, playbooks, and the Ansible command-line tool.
What are Ansible modules?
- Modules are reusable, standalone scripts that Ansible runs on your behalf. Examples include
copy
,yum
, andservice
.
- Modules are reusable, standalone scripts that Ansible runs on your behalf. Examples include
How do you install Ansible?
- You can install Ansible using package managers like
pip
,apt
, oryum
.
- You can install Ansible using package managers like
What is the use of Ansible Galaxy?
- Ansible Galaxy is a repository for Ansible roles, allowing users to share and download roles.
How do you create a new role in Ansible?
- Use the command
ansible-galaxy init <role_name>
to create a new role directory structure.
- Use the command
What is the difference between a playbook and a role in Ansible?
- A playbook is a collection of tasks, while a role is a way to organize playbooks and other files into reusable components.
How do you handle errors in Ansible?
- Use the
ignore_errors
directive or thefailed_when
condition to handle errors.
- Use the
What is Ansible Tower?
- Ansible Tower is an enterprise framework for controlling, securing, and managing your Ansible automation with a UI and REST API.
How do you manage variables in Ansible?
- Variables can be managed in playbooks, inventory files, or variable files.
What is a task in Ansible?
- A task is a single unit of work to be executed on a host, defined in a playbook.
How do you use loops in Ansible?
- Use the
with_items
directive to loop over a list of items.
- Use the
What is a handler in Ansible?
- A handler is a task that runs only when notified by another task.
How do you use conditionals in Ansible?
- Use the
when
directive to execute tasks conditionally.
- Use the
What is the purpose of the
ansible.cfg
file?- The
ansible.cfg
file is used to configure Ansible settings.
- The
How do you secure sensitive data in Ansible?
- Use
ansible-vault
to encrypt sensitive data.
- Use
What is the difference between
command
andshell
modules in Ansible?- The
command
module executes commands without a shell, while theshell
module executes commands through a shell.
- The
How do you use tags in Ansible?
- Tags are used to run specific tasks or plays in a playbook.
What is the use of the
debug
module in Ansible?- The
debug
module prints statements during playbook execution for debugging purposes.
- The
How do you run a specific task in Ansible?
- Use tags and the
--tags
or--skip-tags
options to run specific tasks.
- Use tags and the
What is the
ansible-vault
command used for?ansible-vault
is used to encrypt and decrypt sensitive data.
How do you use templates in Ansible?
- Use the
template
module to process Jinja2 templates and copy them to remote hosts.
- Use the
What is the difference between
include
andimport
in Ansible?include
is dynamic and evaluated at runtime, whileimport
is static and evaluated at parse time.
How do you manage dependencies in Ansible?
- Use roles and the
dependencies
key inmeta/main.yml
to manage dependencies.
- Use roles and the
What is the
ansible-pull
command?ansible-pull
is used to pull playbooks from a VCS repository and execute them on the local machine.
How do you use the
copy
module in Ansible?- The
copy
module copies files from the local machine to remote hosts.
- The
What is the
lineinfile
module used for?- The
lineinfile
module ensures a particular line is present or absent in a file.
- The
How do you use the
file
module in Ansible?- The
file
module manages file properties like permissions, ownership, and symlinks.
- The
What is the
yum
module used for?- The
yum
module manages packages on RPM-based systems.
- The
How do you use the
service
module in Ansible?- The
service
module manages services on remote hosts.
- The
What is the
user
module used for?- The
user
module manages user accounts on remote hosts.
- The
How do you use the
cron
module in Ansible?- The
cron
module manages cron jobs on remote hosts.
- The
What is the
git
module used for?- The
git
module manages Git repositories.
- The
How do you use the
synchronize
module in Ansible?- The
synchronize
module is a wrapper aroundrsync
to synchronize files between hosts.
- The
What is the
wait_for
module used for?- The
wait_for
module waits for a condition to be met before proceeding.
- The
How do you use the
uri
module in Ansible?- The
uri
module interacts with web services.
- The
What is the
setup
module used for?- The
setup
module gathers facts about remote hosts.
- The
How do you use the
command
module in Ansible?- The
command
module runs commands on remote hosts.
- The
What is the
shell
module used for?- The
shell
module runs shell commands on remote hosts.
- The
How do you use the
raw
module in Ansible?- The
raw
module runs raw commands on remote hosts without any processing.
- The
What is the
script
module used for?- The
script
module runs scripts on remote hosts.
- The
How do you use the
win_command
module in Ansible?- The
win_command
module runs commands on Windows hosts.
- The
What is the
win_shell
module used for?- The
win_shell
module runs shell commands on Windows hosts.
- The
How do you use the
win_copy
module in Ansible?- The
win_copy
module copies files to Windows hosts.
- The
What is the
win_service
module used for?- The
win_service
module manages services on Windows hosts.
- The
How do you use the
win_user
module in Ansible?- The
win_user
module manages user accounts on Windows hosts.
- The
I hope this helps with your interview preparation! If you need further details on any of these topics, feel free to ask. Good luck!
Comments