Interview Prep/Ansible/Inventory and Targeting

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 →

  1. Write (or use) a dynamic inventory script/plugin that queries the CMDB and puts maintenance hosts into a maintenance group.
  2. 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.

All Ansible questions Roadmap: Ansible

More on Inventory and Targeting