A host appears in `ansible-inventory --list` but is not matched by `hosts: webservers`. What do you check?
IntermediateScenarioInventory and Targeting
Answer
Situation read → A pattern or group-name mismatch.
What I'd do →
ansible-inventory --graphto see the real group tree.ansible webservers --list-hoststo test the pattern.- Check for typos, case (
Webserversdiffers fromwebservers), and for groups with hyphens (use underscores).
Why → Group names are case-sensitive, and a host can be present in all but in no matching group.
Interview tip → Ansible warns "Could not match supplied host pattern" for a mistyped group; never ignore it.
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