You must configure servers in a private subnet that is only reachable through a bastion.
IntermediateScenarioInventory and Targeting
Answer
Situation read → No direct route from the control node; SSH has to hop.
What I'd do →
- Set a ProxyJump in the inventory group vars.
- Keep the bastion's key and the private hosts' key separate.
# group_vars/private.yml
ansible_ssh_common_args: >-
-o [email protected]
-o StrictHostKeyChecking=accept-new
Test with ansible private -m ping.
Why → Ansible shells out to OpenSSH, so any native SSH feature works with ansible_ssh_common_args.
Interview tip → Mention SSM Session Manager as the bastion-less alternative in AWS (aws_ssm connection plugin).
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 want to run a task on every host in the `db` group and also on localhost in the same playbook.Beginner