Ansible Automation Ansible Inventory & Configuration Management 2 — Questions and Answers
Question 1: What makes an inventory script 'dynamic' in Ansible?
- It is executable and returns JSON inventory data when called (Correct answer)
- It uses YAML format instead of INI
- It auto-discovers hosts via DNS
- It pulls inventory from a database file
Correct answer: It is executable and returns JSON inventory data when called
A dynamic inventory script must be executable and output valid JSON when called with --list or --host arguments.
Question 2: Which command-line argument does Ansible pass to a dynamic inventory script to retrieve all hosts and groups?
- --list (Correct answer)
- --all
- --inventory
- --hosts
Correct answer: --list
Ansible calls the dynamic inventory script with --list to get a full JSON structure of all groups, hosts, and variables.
Question 3: In a YAML inventory file, how do you define a host with a variable?
- hosts:\n server1:\n ansible_user: admin (Correct answer)
- hosts: server1, vars: ansible_user=admin
- host: server1 var: ansible_user=admin
- inventory:\n server1: {ansible_user: admin}
Correct answer: hosts:\n server1:\n ansible_user: admin
YAML inventory uses a nested structure under 'hosts' where each host key can have variable key-value pairs beneath it.
Question 4: What special group in Ansible contains every host in the inventory?
- all (Correct answer)
- ungrouped
- default
- hosts
Correct answer: all
The built-in 'all' group implicitly contains every host defined in the inventory.
Question 5: Which Ansible command can be used to verify and display the parsed inventory?
- ansible-inventory --list (Correct answer)
- ansible --show-inventory
- ansible-playbook --list-hosts
- ansible-config --inventory
Correct answer: ansible-inventory --list
The ansible-inventory --list command outputs the fully parsed inventory as JSON, useful for debugging.
Question 6: Which inventory variable sets the Python interpreter Ansible uses on a managed host?
- ansible_python_interpreter (Correct answer)
- ansible_interpreter
- ansible_python_path
- ansible_exec_python
Correct answer: ansible_python_interpreter
Setting ansible_python_interpreter tells Ansible which Python binary to use on the target host (e.g., /usr/bin/python3).
What makes an inventory script 'dynamic' in Ansible?