Ansible Automation Ansible Inventory & Configuration Management 1 — Questions and Answers
Question 1: What is the default location of the Ansible inventory file?
- /etc/ansible/hosts (Correct answer)
- /etc/ansible/inventory
- /usr/ansible/hosts
- /var/ansible/inventory
Correct answer: /etc/ansible/hosts
Ansible's default inventory file is located at /etc/ansible/hosts unless overridden by ansible.cfg or the -i flag.
Question 2: Which INI-style inventory syntax correctly defines a group called 'webservers'?
- [webservers] (Correct answer)
- {webservers}
- <webservers>
- (webservers)
Correct answer: [webservers]
Inventory groups in INI format are defined using square brackets, such as [webservers].
Question 3: How do you specify a custom inventory file when running an Ansible playbook?
- -i /path/to/inventory (Correct answer)
- --inventory-file=/path
- -f /path/to/inventory
- --hosts=/path/to/inventory
Correct answer: -i /path/to/inventory
The -i flag (short for --inventory) is used to specify a custom inventory file path.
Question 4: What keyword is used in an inventory file to define variables that apply to all hosts in a group?
- [groupname:vars] (Correct answer)
- [groupname:all]
- [groupname:defaults]
- [groupname:settings]
Correct answer: [groupname:vars]
The :vars suffix on a group header (e.g., [webservers:vars]) defines variables that apply to all hosts in that group.
Question 5: Which inventory keyword is used to create a group that contains other groups as members?
- [parentgroup:children] (Correct answer)
- [parentgroup:groups]
- [parentgroup:members]
- [parentgroup:nested]
Correct answer: [parentgroup:children]
The :children suffix on a group header allows you to nest groups inside a parent group.
Question 6: What host pattern would you use to target all hosts in both 'webservers' and 'dbservers' groups?
- webservers:dbservers (Correct answer)
- webservers+dbservers
- webservers,dbservers
- webservers&dbservers
Correct answer: webservers:dbservers
Using a colon between group names (webservers:dbservers) creates a union pattern targeting hosts in either group.
What is the default location of the Ansible inventory file?