Interview Prep/Ansible/Inventory and Targeting

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.

All Ansible questions Roadmap: Ansible

More on Inventory and Targeting