Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is Ansible?
Ansible is an open-source automation tool used for configuration management, application deployment, task automation, and orchestration.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 2. What is an Ansible Playbook?
An Ansible Playbook is a YAML file that defines a set of tasks to be executed on remote hosts. Playbooks are used for automation and orchestration.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 3. How can you define variables in Ansible?
Variables in Ansible can be defined in playbooks, inventory files, or external variable files. They are used to make playbooks more dynamic.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 4. How can you run Ansible playbooks against multiple inventories?
You can use the '-i' option followed by the path to the inventory file when running the 'ansible-playbook' command.
Example:
ansible-playbook -i production_inventory.ini site.yml
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 5. What is the Ansible Galaxy?
Ansible Galaxy is a platform for sharing, discovering, and installing Ansible content, including roles, collections, and playbooks.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 6. What is the purpose of the 'become' keyword in Ansible?
The 'become' keyword is used to execute tasks with escalated privileges, usually by using 'sudo' or 'su'. It is equivalent to 'sudo' in Unix-like systems.
Example:
become: yes
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 7. How can you execute only a specific task from an Ansible playbook?
You can use the '--tags' option followed by the task tag when running the 'ansible-playbook' command to execute specific tasks.
Example:
ansible-playbook site.yml --tags deploy
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 8. How can you check the syntax of an Ansible playbook without executing it?
You can use the 'ansible-playbook' command with the '--syntax-check' option to validate the syntax of a playbook without running it.
Example:
ansible-playbook site.yml --syntax-check
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 9. How can you limit the execution of Ansible tasks to a specific set of hosts?
You can use the '--limit' option followed by the pattern of hosts when running the 'ansible-playbook' command to limit the execution to specific hosts.
Example:
ansible-playbook site.yml --limit web_servers
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 10. How can you use loops in Ansible playbooks?
Ansible supports loops using the 'with_items' keyword. It allows tasks to be repeated for each item in a list.
Example:
with_items:
- item1
- item2
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 11. How can you include external files in Ansible playbooks?
The 'include' statement is used to include external YAML files in Ansible playbooks. It allows for better organization and reuse of playbook components.
Example:
include: tasks/common-tasks.yml
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 12. How can you define and use roles in Ansible playbooks?
Roles are defined in separate directories and can be included in playbooks using the 'roles' keyword. They enhance playbook organization and reusability.
Example:
roles:
- common
- web_server
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 13. How can you check if a file or directory exists in Ansible?
The 'stat' module in Ansible can be used to check the existence of a file or directory. The result can be checked using the 'stat.exists' attribute.
Example:
stat:
path: /path/to/file.txt
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 14. How can you override variables in Ansible?
Variables in Ansible can be overridden at different levels, including playbooks, inventory files, and the command line. The precedence order determines which value is used.
Example:
ansible-playbook site.yml -e 'variable_name=new_value'
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Intermediate / 1 to 5 years experienced level questions & answers
Ques 15. Explain the difference between Ansible and other configuration management tools.
Ansible is agentless, uses simple YAML syntax, and doesn't require a master-server setup. Other tools like Puppet and Chef rely on agents and a master-server architecture.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 16. Explain the role of an Ansible Handler.
An Ansible Handler is a special task triggered only if another task changes a system state. Handlers are used to restart services or perform similar actions after a change.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 17. What is the purpose of Ansible roles?
Roles in Ansible provide a way to organize and reuse code. They consist of tasks, handlers, variables, and other related files structured in a directory hierarchy.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 18. Explain the concept of idempotence in Ansible.
Idempotence means that the result of an operation is the same regardless of how many times it is executed. Ansible plays and tasks should be designed to be idempotent.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 19. How can you encrypt sensitive data in Ansible?
Ansible provides the 'ansible-vault' command to encrypt sensitive data, such as passwords and secret keys.
Example:
ansible-vault encrypt secret.yml
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 20. Explain Ansible facts.
Ansible facts are pieces of system information collected during playbook execution. They provide details about the target system, such as hardware, network, and OS.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 21. What is the purpose of the 'notify' keyword in Ansible?
The 'notify' keyword is used to trigger handlers. It specifies a task or a list of tasks to be executed if the associated task results in a change.
Example:
notify: restart apache
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 22. What is the purpose of the 'register' keyword in Ansible?
The 'register' keyword is used to capture the output of a task and store it in a variable. This variable can be used later in the playbook.
Example:
register: result
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 23. Explain Ansible dynamic inventories.
Dynamic inventories in Ansible are scripts or programs that generate inventory information dynamically. They are useful in dynamic or cloud environments.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 24. What is the purpose of the 'when' keyword in Ansible?
The 'when' keyword is a conditional statement in Ansible. It is used to execute a task based on a specified condition, improving playbook flexibility.
Example:
when: ansible_os_family == 'Debian'
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 25. Explain the purpose of Ansible Tower.
Ansible Tower is a web-based UI and API for managing Ansible. It provides a dashboard, role-based access control, job scheduling, and other features.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 26. Explain the purpose of Ansible Facts caching.
Ansible Facts caching is the process of storing facts about remote systems locally to improve performance. It reduces the need to gather facts on each playbook run.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 27. What is the purpose of the 'delegate_to' keyword in Ansible?
The 'delegate_to' keyword is used to run a task on a different host than the one specified in the playbook. It is useful for offloading tasks to specific hosts.
Example:
delegate_to: backup_server
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 28. Explain Ansible dynamic variables.
Dynamic variables in Ansible are variables whose values are generated or fetched dynamically during playbook execution. They provide flexibility in configuration.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Ques 29. Explain Ansible Tower Workflows.
Ansible Tower Workflows allow the creation of complex job workflows by combining multiple playbooks and job templates. They provide a visual representation of the workflow.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Experienced / Expert level questions & answers
Ques 30. How can you create custom Ansible modules?
Custom Ansible modules can be created using Python. They should follow the Ansible module development guidelines and use the 'ansible.module_utils' library.
Save For Revision
Save For Revision
Bookmark this item, mark it difficult, or place it in a revision set.
Log in to save bookmarks, difficult questions, and revision sets.
Most helpful rated by users:
فروقات ذات صلة
Related interview subjects
| Express.js اسئلة واجوبة المقابلات - Total 30 questions |
| Ansible اسئلة واجوبة المقابلات - Total 30 questions |
| ES6 اسئلة واجوبة المقابلات - Total 30 questions |
| Electron.js اسئلة واجوبة المقابلات - Total 24 questions |
| RxJS اسئلة واجوبة المقابلات - Total 29 questions |
| NodeJS اسئلة واجوبة المقابلات - Total 30 questions |
| ExtJS اسئلة واجوبة المقابلات - Total 50 questions |
| jQuery اسئلة واجوبة المقابلات - Total 22 questions |
| Vue.js اسئلة واجوبة المقابلات - Total 30 questions |
| Svelte.js اسئلة واجوبة المقابلات - Total 30 questions |
| Shell Scripting اسئلة واجوبة المقابلات - Total 50 questions |
| Next.js اسئلة واجوبة المقابلات - Total 30 questions |
| Knockout JS اسئلة واجوبة المقابلات - Total 25 questions |
| TypeScript اسئلة واجوبة المقابلات - Total 38 questions |
| PowerShell اسئلة واجوبة المقابلات - Total 27 questions |
| Terraform اسئلة واجوبة المقابلات - Total 30 questions |
| JCL اسئلة واجوبة المقابلات - Total 20 questions |
| JavaScript اسئلة واجوبة المقابلات - Total 59 questions |
| Ajax اسئلة واجوبة المقابلات - Total 58 questions |