Exercise 1: Why a Static EC2 Inventory Goes Stale With Autoscaling — Possible Solution ==================================================================== -- Why a static IP-based inventory becomes inaccurate within days -- -- -- An autoscaling group's whole purpose is to add and remove EC2 -- instances automatically in response to load -- instances get -- created, terminated, and replaced on a schedule the team doesn't -- directly control, sometimes multiple times a day during variable -- traffic. A static inventory file lists specific IP addresses at the -- moment someone wrote it down -- it has no way to know that an -- instance was terminated an hour later, or that a brand-new instance -- just came up with a completely different IP to replace it. Within -- days, a meaningful fraction of the IPs in that file would belong to -- instances that no longer exist, and a meaningful number of currently -- running instances would be missing from the file entirely, since -- nobody manually updated it to include them. Playbooks run against -- this file would either fail trying to reach dead IPs, or -- worse -- -- silently skip real, currently-running instances that never got -- added. -- How a dynamic inventory plugin avoids this -- -- -- A dynamic inventory plugin like the chapter's own aws_ec2 example -- doesn't read a list written down in advance at all -- it queries -- AWS's own API directly, at the moment ansible-playbook is actually -- run, asking "which instances currently match these filters right -- now." Because this query happens fresh every single run, the -- resulting inventory always reflects the autoscaling group's actual, -- current membership -- newly created instances are picked up -- automatically the next time the playbook runs, and terminated ones -- simply stop appearing, with no human ever needing to update a file -- by hand. WHY THIS WORKS AS AN ANSWER ------------------------------ This explains concretely why autoscaling specifically breaks a static, IP-based inventory (instances are created/destroyed outside anyone's direct control), then explains the dynamic inventory fix by contrasting "written down in advance" against "queried live at run time" rather than just asserting dynamic inventory is better.