You do not know which of 300 servers still run the vulnerable OpenSSL version. How do you find out fast?
IntermediateScenarioInventory and Targeting
Answer
Situation read → An audit task: read-only, wide, and urgent.
What I'd do →
- Use an ad-hoc command or
package_factswith a high fork count. - Collect output to a file.
ansible all -f 50 -m ansible.builtin.shell -a "openssl version" -o | tee openssl-audit.txt
ansible all -m ansible.builtin.package_facts -a "manager=auto" --tree /tmp/facts
-o gives one line per host, which is greppable.
Why → Ad-hoc is the right tool for read-only questions; no playbook needed.
Interview tip → For recurring audits, convert it to a playbook that writes a CSV with lineinfile or copy on the controller.
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 must configure servers in a private subnet that is only reachable through a bastion.Intermediate