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_errorsdirective or thefailed_whencondition 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_itemsdirective 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
whendirective to execute tasks conditionally.
- Use the
What is the purpose of the
ansible.cfgfile?- The
ansible.cfgfile is used to configure Ansible settings.
- The
How do you secure sensitive data in Ansible?
- Use
ansible-vaultto encrypt sensitive data.
- Use
What is the difference between
commandandshellmodules in Ansible?- The
commandmodule executes commands without a shell, while theshellmodule 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
debugmodule in Ansible?- The
debugmodule prints statements during playbook execution for debugging purposes.
- The
How do you run a specific task in Ansible?
- Use tags and the
--tagsor--skip-tagsoptions to run specific tasks.
- Use tags and the
What is the
ansible-vaultcommand used for?ansible-vaultis used to encrypt and decrypt sensitive data.
How do you use templates in Ansible?
- Use the
templatemodule to process Jinja2 templates and copy them to remote hosts.
- Use the
What is the difference between
includeandimportin Ansible?includeis dynamic and evaluated at runtime, whileimportis static and evaluated at parse time.
How do you manage dependencies in Ansible?
- Use roles and the
dependencieskey inmeta/main.ymlto manage dependencies.
- Use roles and the
What is the
ansible-pullcommand?ansible-pullis used to pull playbooks from a VCS repository and execute them on the local machine.
How do you use the
copymodule in Ansible?- The
copymodule copies files from the local machine to remote hosts.
- The
What is the
lineinfilemodule used for?- The
lineinfilemodule ensures a particular line is present or absent in a file.
- The
How do you use the
filemodule in Ansible?- The
filemodule manages file properties like permissions, ownership, and symlinks.
- The
What is the
yummodule used for?- The
yummodule manages packages on RPM-based systems.
- The
How do you use the
servicemodule in Ansible?- The
servicemodule manages services on remote hosts.
- The
What is the
usermodule used for?- The
usermodule manages user accounts on remote hosts.
- The
How do you use the
cronmodule in Ansible?- The
cronmodule manages cron jobs on remote hosts.
- The
What is the
gitmodule used for?- The
gitmodule manages Git repositories.
- The
How do you use the
synchronizemodule in Ansible?- The
synchronizemodule is a wrapper aroundrsyncto synchronize files between hosts.
- The
What is the
wait_formodule used for?- The
wait_formodule waits for a condition to be met before proceeding.
- The
How do you use the
urimodule in Ansible?- The
urimodule interacts with web services.
- The
What is the
setupmodule used for?- The
setupmodule gathers facts about remote hosts.
- The
How do you use the
commandmodule in Ansible?- The
commandmodule runs commands on remote hosts.
- The
What is the
shellmodule used for?- The
shellmodule runs shell commands on remote hosts.
- The
How do you use the
rawmodule in Ansible?- The
rawmodule runs raw commands on remote hosts without any processing.
- The
What is the
scriptmodule used for?- The
scriptmodule runs scripts on remote hosts.
- The
How do you use the
win_commandmodule in Ansible?- The
win_commandmodule runs commands on Windows hosts.
- The
What is the
win_shellmodule used for?- The
win_shellmodule runs shell commands on Windows hosts.
- The
How do you use the
win_copymodule in Ansible?- The
win_copymodule copies files to Windows hosts.
- The
What is the
win_servicemodule used for?- The
win_servicemodule manages services on Windows hosts.
- The
How do you use the
win_usermodule in Ansible?- The
win_usermodule 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