Interview Prep/Ansible/Inventory and Targeting

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.

All Ansible questions Roadmap: Ansible

More on Inventory and Targeting