Skip to main content

Tool to generate Packer configurations from YAML and Jinja2

Project description

packer-config-gen

PyPI version License Build Status

packer-config-gen (pcg) streamlines your golden image pipeline by separating data (YAML) from build logic (Jinja2). It serves as an orchestration layer that takes clean, inheritable VM specifications and automatically renders:

  1. Complex Packer manifests (.pkr.hcl).
  2. OS autoinstall configurations (Ubuntu autoinstall, Preseed, Kickstart).

Define your infrastructure once in YAML, and let pcg handle the boilerplate.

Prerequisites

  • Python 3.13

Installation

Available on PyPI

pip install packer-config-gen

Usage

The tool expects the following structure in your working directory:

.
├── .env                    # Secrets (SSH_PASS, API_TOKEN)
├── configs/
│   ├── hypervisor.yaml     # General settings (Proxmox/vSphere/VirtualBox)
│   └── os/
│       └── ubuntu.yaml  # OS-specific settings
├── templates/
│   ├── hypervisor.pkr.hcl.j2  # Main Packer template
│   └── subiquity/             # Installer template folder
│       ├── user-data.j2
│       └── meta-data.j2
└── artifacts/              # Output directory (auto-generated)

Examples of repositories that use this utility:

1. OS configuration example (configs/os/ubuntu.yaml):

packer_builder_name: "ubuntu"
guest_os_type: "Ubuntu_64"
vm_name: "ubuntu-24.04-lts"

iso_config:
  url: "https://releases.ubuntu.com/noble"
  file: "ubuntu-24.04.3-live-server-amd64.iso"
  checksum: "file:https://releases.ubuntu.com/noble/SHA256SUMS"

boot_command:
  - "e<wait><down><down><down><end><bs><bs><bs><bs><wait>"
  - "ipv6.disable=1 \"ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/\" autoinstall ---<wait>"
  - "<f10><wait>"

installer: "subiquity"
installer_files:
  - meta-data
  - user-data

2. Environment variables example (.env):

USER="user"
# Use: mkpasswd -m sha-512
PASSWORD='$6$vPP.....'

SSH_PUBLIC_KEY='ssh-ed25519 AAAAbbbbbbbccccccc....'
SSH_PRIVATE_KEY_FILE="/home/user/.ssh/key"

3. Hypervisor configuration example (configs/hypervisor.yaml)

system_settings:
  cpus: 2
  memory: 2048
  gfx_vram_size: 16
  firmware_type: "efi"
  export_format: "ova"
  communicator: "ssh"
  timezone: ""

vboxmanage_commands:
  - [ "modifyvm", "{{.Name}}", "--audio", "none" ]
  - [ "modifyvm", "{{.Name}}", "--vrde", "off" ]

iso_config:
  interface: "sata"
  source: ".cache/iso" 

disk_config:
  size: 150000
  interface: "sata"
  is_discard: false
  is_nonrotational: false

guest_additions:
  mode: "upload"
  path: "/tmp/VBoxGuestAdditions.iso"

ssh_config:
  username: ""
  password: ""
  private_key_file: ""
  pub_key: ""
  timeout: "30m"

boot_control:
  boot_wait: "5s"
  shutdown_command: "sudo shutdown -P now"

Run the pcg command, passing the OS configuration filename:

pcg --os ubuntu

Result: The following files will be created in the artifacts/ubuntu/ folder:

- ubuntu.pkr.hcl
- cidata/user-data
- cidata/meta-data

Now you can start the build:

packer build artifacts/ubuntu/ubuntu.pkr.hcl

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packer_config_gen-1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

packer_config_gen-1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file packer_config_gen-1.1.tar.gz.

File metadata

  • Download URL: packer_config_gen-1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for packer_config_gen-1.1.tar.gz
Algorithm Hash digest
SHA256 48e6c61efcb7a7b9d98c635faccbb38029ca2ee14b18df97cdd1a03315d8f4bd
MD5 ec60b4171f201bf90192f60add30717a
BLAKE2b-256 9a38a6d86aec8a82db960285ff2d998fe738665d7c446c9e0f6b0567bb9f47e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for packer_config_gen-1.1.tar.gz:

Publisher: ci.yaml on serhii9132/packer-config-gen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file packer_config_gen-1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for packer_config_gen-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5984364747a2fbbc5a224027bea837ca5638a43e319a4d9bfa23c1be67e6be0
MD5 fb3ab7f604ea2b17e70ef31a48deab35
BLAKE2b-256 e96c1de37532aac4b258086736b96591f9b57c36a7f2e4702f2ac63aa0a65fd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for packer_config_gen-1.1-py3-none-any.whl:

Publisher: ci.yaml on serhii9132/packer-config-gen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page