Golden_OS_Images

Golden OS Images

A project for building and managing golden (pre-configured) operating system images using Packer and Ansible, with automated deployment to Azure.

Overview

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.

Project Structure

├── 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

Prerequisites

Getting Started

1. Configure Azure Credentials

Set the following secret in your GitHub repository:

2. Local Testing

To build the image locally:

cd packer/ubuntu
packer build -var-file="variables.pkr.hcl" ubuntu.pkr.hcl

3. Automated Build via GitHub Actions

Push to the main branch to trigger the automated build workflow:

git push origin main

The workflow will:

  1. Check out the code
  2. Authenticate with Azure
  3. Build the golden image with Packer
  4. Run Ansible provisioning (base, hardening, monitoring)
  5. Upload the image to Azure Storage (if configured)

Roles

Customize these roles by editing the corresponding tasks/main.yml and defaults/main.yml files.

Variables

Edit packer/ubuntu/variables.pkr.hcl to customize:

Usage

Building a Golden Image

packer build packer/ubuntu

Validating Configuration

bash scripts/validate.sh

Generating Metadata

bash scripts/generate-metadata.sh

Output

CI/CD Pipeline

The GitHub Actions workflow automates the entire process:

Contribution

  1. Create a feature branch: git checkout -b feature/your-feature
  2. Make changes and test locally
  3. Push and create a pull request
  4. Merge to main to trigger the build pipeline