Interview Prep/Ansible/Inventory and Targeting

Your inventory has hundreds of hosts named `web001` through `web300`. How do you write it compactly?

BeginnerScenarioInventory and Targeting
Answer

Situation read → Repetition that ranges solve.

What I'd do →

[web]
web[001:300].example.com

[db]
db-[a:c].example.com

In YAML inventory you can use the same bracket ranges as the host key.

Why → Ranges expand at parse time, and zero padding is preserved when you write 001.

Interview tip → Verify with ansible web --list-hosts | wc -l.

All Ansible questions Roadmap: Ansible

More on Inventory and Targeting