chriswayg / packer-proxmox-templates

:package: Packer templates for building Proxmox KVM images from ISO
170 stars 49 forks source link

packer-proxmox-templates

:package: Packer templates for building Proxmox KVM images from ISO

Debian v10 (buster) Packer Template using Packer Proxmox Builder to build a Proxmox VM image template

Ubuntu 18.04 (bionic) Packer Template using Packer Proxmox Builder to build a Proxmox VM image template

Ubuntu 20.04 (focal) Packer Template using Packer Proxmox Builder to build a Proxmox VM image template

OpenBSD 6 Packer Template using Packer Proxmox Builder to build a Proxmox VM image template

Alpine Linux Packer Template using Packer Proxmox Builder to build a Proxmox VM image template

Alpine Linux Packer Template using QEMU Builder to build a KVM image usable in Openstack or Proxmox

Proxmox KVM image templates

Check Prerequisites

The build script which will run the packer template is configured to run on the Proxmox server. Thus the following pre-requisites should be installed on the Proxmox server:

printf  "Proxmox $(pveversion)\n"
apt -y install unzip
packer_ver=1.5.5
wget https://releases.hashicorp.com/packer/${packer_ver}/packer_${packer_ver}_linux_amd64.zip
sudo unzip packer_${packer_ver}_linux_amd64.zip -d /usr/local/bin
packer --version
apt -y install python3-pip
pip3 install ansible==2.9.7
pip3 install py-bcrypt
pip3 install j2cli[yaml]

Download the latest tagged release of packer-proxmox-templates onto the Proxmox server

wget https://github.com/chriswayg/packer-proxmox-templates/archive/v1.7.zip && unzip v1.7.zip && cd packer-proxmox-templates-*

Usage

On the Proxmox Server with Packer installed:

cd OSname-xy-amd64-proxmox

# for example
cd debian-10-amd64-proxmox
cd ubuntu-18.04-amd64-proxmox
cd openbsd-6-amd64-proxmox
../build.sh proxmox

Build Options

../build.sh (proxmox|debug [new_VM_ID])

proxmox    - Build and create a Proxmox VM template
debug      - Debug Mode: Build and create a Proxmox VM template

VM_ID     - VM ID for new VM template (or use default from build.conf)

Enter Passwords when prompted or provide them via ENV variables:
(use a space in front of ' export' to keep passwords out of bash_history)
 export proxmox_password=MyLoginPassword
 export ssh_password=MyPasswordInVM

Build environment

The Packer templates have been tested with the following versions of Packer and Ansible. If you use different versions, some details may need to be updated.

printf  "$(lsb_release -d) $(cat /etc/debian_version)\n" && \
  printf  "Proxmox $(pveversion)\n" &&
  packer version && \
  ansible --version |  sed -n '1p' && \
  ansible --version |  sed -n '6p' && \
  j2 --version

        Description:    Debian GNU/Linux 10 (buster) 10.3
        Proxmox pve-manager/6.1-8/806edfe1 (running kernel: 5.3.18-3-pve)
        Packer v1.5.5
        ansible 2.9.7
          python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]
        j2cli 0.3.10, Jinja2 2.11.2

NOTE: For security reasons it would be preferable to build the Proxmox template images on a local Proxmox staging server (for example in a VM) and then to transfer the Proxmox templates using migration onto the live server(s).

It should also be possible to use Packer remotely and to control VM creation remotely via Ansible. The Packer template and the scripts would have to be modified accordingly. If you have it working remotely, please make a pull request.