Golden images (Packer) versus configuring at boot with Ansible: how do you choose?
AdvancedProductionProject Structure and Design
Answer
Bake what is slow, stable and shared (OS hardening, runtimes, agents) into an AMI with Packer and the Ansible provisioner. Configure at boot only what varies per environment or instance (hostnames, endpoints, secrets) via user-data, cloud-init, or ansible-pull.
Baking gives fast, consistent autoscaling and fewer boot-time failures, but needs an image pipeline and rebuilds for every patch. Boot-time Ansible gives flexibility, but slows scale-out and fails when package repos or the network are down at that moment. We bake, and keep Ansible as the single source of truth for both stages, so the same roles produce the image and later correct drift.
More on Project Structure and Design
What does a production Ansible repository look like?BeginnerMonorepo or separate repos for roles? How do you decide?IntermediateHow do you structure inventories for dev, stage and prod?BeginnerHow do you prevent someone from running a playbook against production by accident?IntermediateWhat does "thin playbooks, fat roles" mean?IntermediateWhat makes a well-designed role?Intermediate