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:

export USERNAME="user"

export PASSWORD='$6$vPP.....'    # Use: mkpasswd -m sha-512

export SSH_PUBLIC_KEY='ssh-ed25519 AAAAbbbbbbbccccccc....'
export 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.3.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.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: packer_config_gen-1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 6d63636071a6202973690a116a03b46f651dd1c49eb8b1ca055812911370104f
MD5 e7d11f05bb90b845ef99f10d9904a4db
BLAKE2b-256 379ce1f235069e5789982bc040b6232ac0c208571ec621a38215f1ce772389ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for packer_config_gen-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8615f261224aecfc024cf7adc3290df21f2a43d1d7ebb2b7b63a92adfbf99e0d
MD5 3003ceb0ec420aad92700bff42e9bcc5
BLAKE2b-256 5b414651989c4b1389e717d172737847d6d5d70d3ffebc7fc33543e8e1cff295

See more details on using hashes here.

Provenance

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