Interview Prep/Linux/Patching, Automation & Golden Images

How do you build golden images with Packer?

IntermediateProductionPatching, Automation & Golden Images
Answer
source "amazon-ebs" "base" {
  region        = "ap-south-1"
  instance_type = "t3.small"
  ssh_username  = "ubuntu"
  ami_name      = "base-ubuntu24-{{timestamp}}"
  source_ami_filter {
    filters     = { name = "ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*" }
    owners      = ["099720109477"]
    most_recent = true
  }
}
build {
  sources = ["source.amazon-ebs.base"]
  provisioner "ansible" { playbook_file = "./harden.yml" }
}
packer init . && packer validate . && packer build .

Run it in CI on a schedule, then scan and test the result before promoting.

All Linux questions Roadmap: Linux

More on Patching, Automation & Golden Images