A new engineer asks how you know which inventory variables actually apply to a host.
BeginnerScenarioInventory and Targeting
Answer
Situation read → Debugging variable merging.
What I'd do →
ansible-inventory -i inventories/prod --host web01
ansible web01 -m ansible.builtin.debug -a "var=hostvars[inventory_hostname]"
Why → The first prints inventory-derived variables after merging; the second shows what a running play sees, including facts and extra vars.
Interview tip → Mention --vars with --graph to show variables per group.
More on Inventory and Targeting
You are handed a fresh Ansible project and 10 servers. How do you make sure Ansible can reach all of them before writing any playbook?BeginnerYour team keeps prod and staging hosts in one inventory file and someone ran a playbook on prod by mistake. How do you prevent it?IntermediateYou need to run a playbook on only the web servers in Mumbai that are not in the canary group. How?BeginnerServers are autoscaled in AWS and IPs change daily. How do you keep the inventory accurate?IntermediateA host is reachable by SSH on port 2222 with a different user from all others. How do you model that?BeginnerYou must configure servers in a private subnet that is only reachable through a bastion.Intermediate