You need to run a playbook on only the web servers in Mumbai that are not in the canary group. How?
BeginnerScenarioInventory and Targeting
Answer
Situation read → A set-algebra host pattern: intersect two groups, exclude a third.
What I'd do →
ansible-playbook site.yml --limit 'web:&mumbai:!canary'
ansible-playbook site.yml --limit 'web:&mumbai:!canary' --list-hosts
Always run --list-hosts first to see what the pattern resolves to.
Why → :& is intersection and :! is exclusion; quoting prevents the shell from eating ! and &.
Interview tip → Know that --limit narrows the play's hosts:; it cannot add hosts the play never targeted.
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?IntermediateServers 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.IntermediateYou want to run a task on every host in the `db` group and also on localhost in the same playbook.Beginner