A host is reachable by SSH on port 2222 with a different user from all others. How do you model that?
BeginnerScenarioInventory and Targeting
Answer
Situation read → One exception to otherwise uniform connection settings.
What I'd do → Set host-level connection variables on that host only.
[web]
web01
web02
legacy01 ansible_port=2222 ansible_user=admin ansible_ssh_private_key_file=~/.ssh/legacy.pem
Why → Inventory-level variables beat group defaults for that host while leaving everyone else untouched.
Interview tip → If the exception grows to several settings, move it to host_vars/legacy01.yml.
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?IntermediateYou 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