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?
BeginnerScenarioInventory and Targeting
Answer
Situation read → No playbook yet; the first risk is connectivity, not logic.
What I'd do →
- Write an inventory with the hosts and
ansible_user/key settings. - Run
ansible all -i inventory.ini -m ping. - For failures, rerun with
-vvvon one host.
ansible all -i inventory.ini -m ansible.builtin.ping
ansible web01 -i inventory.ini -m ansible.builtin.ping -vvv
Why → ping tests SSH login, Python on the target and module execution in one shot, so a pong means real playbooks will run.
Interview tip → Say that ping is not ICMP; it is a full Ansible round trip.
More on Inventory and Targeting
Your 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 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