A project for building and managing golden (pre-configured) operating system images using Packer and Ansible, with automated deployment to Azure.
This project automates the creation of golden Ubuntu images with hardened security configurations and monitoring setup. The built images are stored as Azure Managed Images in your resource group.
├── ansible/ # Ansible playbooks and roles for image provisioning
│ ├── playbooks/ # Main playbooks
│ │ └── configure.yml # Image configuration playbook
│ └── roles/ # Reusable Ansible roles
│ ├── base/ # Base OS configuration
│ ├── hardening/ # Security hardening
│ └── monitoring/ # Monitoring setup
├── packer/ # Packer configurations
│ └── ubuntu/ # Ubuntu image builder
│ ├── ubuntu.pkr.hcl # Main Packer configuration
│ ├── variables.pkr.hcl # Packer variables
│ └── version.json # Version information
├── scripts/ # Utility scripts
│ ├── generate-metadata.sh # Generate image metadata
│ └── validate.sh # Validation scripts
└── .github/workflows/ # CI/CD pipelines
└── build-image.yml # Automated build workflow
Set the following secret in your GitHub repository:
AZURE_CREDENTIALS - Azure service principal credentials (JSON format)To build the image locally:
cd packer/ubuntu
packer build -var-file="variables.pkr.hcl" ubuntu.pkr.hcl
Push to the main branch to trigger the automated build workflow:
git push origin main
The workflow will:
Customize these roles by editing the corresponding tasks/main.yml and defaults/main.yml files.
Edit packer/ubuntu/variables.pkr.hcl to customize:
image_name - Base image namelocation - Azure regionresource_group - Target resource groupimage_sku - Ubuntu versionpacker build packer/ubuntu
bash scripts/validate.sh
bash scripts/generate-metadata.sh
{image_name}-golden-{date}The GitHub Actions workflow automates the entire process:
main branchUploads to storage (optional)
ansible-playbook --syntax-checkgit checkout -b feature/your-featuremain to trigger the build pipeline