Your playbook should skip hosts that are currently in maintenance, tracked in a CMDB.
AdvancedScenarioInventory and Targeting
Answer
Situation read → An external system decides membership; the inventory must reflect it.
What I'd do →
- Write (or use) a dynamic inventory script/plugin that queries the CMDB and puts maintenance hosts into a
maintenancegroup. - Exclude it in every run with a default limit, or enforce it in the play.
- hosts: "all:!maintenance"
roles: [baseline]
Why → Excluding by group in the play makes the rule impossible to forget at the command line.
Interview tip → Dynamic scripts must support --list and --host <name> and print JSON.
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