Skip to main content

Tool to generate Packer configurations from YAML and Jinja2

Project description

packer-config-gen

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:

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.2.tar.gz (5.0 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.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: packer_config_gen-1.2.tar.gz
  • Upload date:
  • Size: 5.0 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.2.tar.gz
Algorithm Hash digest
SHA256 66308b28b60a12f494b4224f171a9c4eef97624b3dc2e50f8abeddea5f453bdc
MD5 f2beffafffdd00c59c90b6a4b73dbb73
BLAKE2b-256 af18974fd54d1d1e4e1db4c8eff3a372595eeeb47edae7f1d1bedb1627428f41

See more details on using hashes here.

Provenance

The following attestation bundles were made for packer_config_gen-1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for packer_config_gen-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f79e314906346a3970286181a680466507516a218d7a3d811936f312e6ce602c
MD5 c12a0e32692d54a9d6e929826e3cfbe8
BLAKE2b-256 413964498ae38639e9ee8695b0aa68d1096f7fa61ab6d39809c57a81a429cff2

See more details on using hashes here.

Provenance

The following attestation bundles were made for packer_config_gen-1.2-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