Interview Prep/Ansible/Variables, Facts and Precedence

How do you override a variable for one host only?

BeginnerConceptVariables, Facts and Precedence
Answer

Put it in host_vars/<hostname>.yml (or inline in the inventory). Host variables beat group variables of any group, so this is the clean per-host exception.

# inventory/host_vars/web3.yml
nginx_worker_processes: 8

For a one-off run, pass -e with --limit web3. Keep exceptions rare, because every host-specific override makes the fleet harder to reason about.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence