- Jinja 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| defaults | ||
| handlers | ||
| meta | ||
| tasks | ||
| templates | ||
| .gitignore | ||
| CHANGELOG.md | ||
| CLAUDE.md | ||
| LICENSE | ||
| README.md | ||
| requirements.yml | ||
proxmox
Configures a Proxmox VE host and converges it to one of two target states, regardless of what's currently applied:
- Unlicensed (default): no-subscription APT repos, enterprise repos disabled, login popup suppressed.
- Licensed (
proxmox_license_keyset): key registered viapvesubscription, enterprise repos enabled, no-subscription repo removed, popup patch reverted.
sshd_config hardening applies independently of licensing mode.
It also provides two standalone task files, vm and container, for commissioning individual VMs/LXC containers — call these directly from a service's own playbook rather than declaring a fleet-wide list here. See VM and LXC containers below.
Requirements
- Proxmox VE host (Debian-based)
community.proxmoxcollection (requirements.yml) — only needed if you useproxmox_vms_images/proxmox_lxc_templatesor thevm/containertask files
Variables
| Variable | Default | Description |
|---|---|---|
proxmox_repo_suite |
trixie |
Debian suite/codename backing the PVE repos. |
proxmox_license_key |
~ |
Subscription key. Set to switch to licensed mode. |
proxmox_manage_ceph_repo |
true |
Toggle the Ceph repo in ceph.sources. Set false on hosts without Ceph. |
proxmox_apt_update |
true |
Refreshes the apt cache after applying repository changes. |
proxmox_proxmoxer_version |
2.3.0 |
Pinned pip version of proxmoxer installed on the target host. Required (>=2.3) by community.proxmox's modules; installed via pip since Debian's apt package doesn't offer >=2.3. |
proxmox_uninstall |
false |
Reverts every change made by this role (host config only — see below). |
proxmox_nodes |
{} |
Shared node/API registry. Required by proxmox_vms_images, proxmox_lxc_templates, and every vm/container call. |
proxmox_vms_images |
[] |
Cloud-init images to download centrally. See Image and template acquisition. |
proxmox_lxc_templates |
[] |
LXC OS templates to fetch centrally. See Image and template acquisition. |
proxmox_firewall_management_cidrs |
[] |
CIDRs that always keep full access to any VM/container with firewall_ports set. See Firewall. |
Usage
- hosts: pve_hosts
become: true
roles:
- proxmox
To license the host:
proxmox_license_key: "{{ vault_proxmox_license_key }}"
This is idempotent in both directions: switching proxmox_license_key between set and unset always reverts whatever the other mode applied (repos, popup patch, subscription key, and the apt auth files under /etc/apt/auth.conf.d/ that pvesubscription writes but doesn't clean up on its own).
Uninstall
proxmox_uninstall: true
Reverts every host-level change this role can make, including deregistering any subscription key it registered. Does not remove VMs or LXC containers — see Decommissioning below.
VM and LXC containers
There's no fleet-wide "list of VMs" variable here — each service owns its own single VM/container definition and commissions it as the first step of its own playbook, by calling this role's vm/container task files directly:
- name: Commission the database VM
ansible.builtin.include_role:
name: proxmox
tasks_from: vm
vars:
proxmox_vm:
name: db01
node: pve10
root_disk:
image: "{{ proxmox_image_debian13 }}"
nics:
- name: eth0
ip: 10.13.37.20/24
gateway: 10.13.37.1
ssh_key: "{{ vault_db01_ssh_key }}"
Requires proxmox_nodes to already be set (typically centrally, e.g. group_vars/all/). Re-running this converges the VM to the given definition; hardware (NICs, disks, pool) is only applied at creation, everything else is reconciled on every run.
The root disk is imported via qm importdisk/qm set over SSH, not the API — import_from with a raw path is rejected under token auth (the recommended proxmox_nodes style).
qemu-guest-agent is installed and enabled via cloud-init automatically (needed for the ARP-warming step below to reach the VM).
After start, every NIC with a gateway gets pinged from inside the guest (VM or container) on every run — refreshes OPNsense's ARP cache for that IP, which can go stale independently of the guest itself. Retried on failure (the interface isn't always immediately up right after create/start): VMs up to 30 times, 10s apart; containers up to 10 times, 3s apart (LXC boots much faster than a full VM's cloud-init cycle, so needs far less headroom).
proxmox_vm fields
| Field | Required | Description |
|---|---|---|
name |
yes | Name (and hostname) of the VM |
node |
yes | Node key from proxmox_nodes |
state |
no | present (default) or absent — see Decommissioning |
vmid |
no | Proxmox VM ID; auto-assigned if omitted. If set, asserted cluster-wide against every other VM/container — fails fast if it's already assigned to a differently-named machine |
root_disk.image |
yes | Path to a cloud-init image |
root_disk.size |
no | GB, default 10 |
root_disk.storage |
no | Defaults to the node's default_storage |
nics |
yes | List of NICs (net0/ipconfig0, net1/ipconfig1, ... in NIC order) |
nics[].name |
yes | Interface name |
nics[].ip/.gateway |
no | Static IP in CIDR + gateway; omit both for DHCP |
nics[].vlan |
no | VLAN tag |
nics[].bridge |
no | Defaults to vmbr0 |
ssh_key |
yes | Cloud-init SSH key for root login (ciuser is pinned to root, not the image's default user) |
sockets/cores/memory |
no | Defaults: 1/2/4096 |
balloon |
no | Minimum memory in MB under host memory pressure (ballooning). Unset: no ballooning |
cpu |
no | Default x86-64-v2-AES (a portable microarchitecture baseline, not full host passthrough). Reconciled every run, not creation-only. Bump to x86-64-v3 (or higher - see pvesh get /nodes/<node>/capabilities/qemu/cpu for every built-in type this Proxmox version offers) for guest software requiring AVX/AVX2 - e.g. MongoDB 5.0+ crashes with SIGILL on x86-64-v2-AES, which stops at SSE4.2/AES-NI. Requires the physical node's CPU to actually support the target level, and a VM reboot to take effect. |
nameservers |
no | String or list |
pool |
no | Created automatically if it doesn't exist |
tags |
no | List of tags |
start_after_creation |
no | Default true; only applies the first time the VM is created |
data_disks |
no | List of {name, size, storage, mountpoint, iothread, discard, cache, ssd} extra disks. mountpoint (optional, absolute path) formats the disk ext4 and mounts it inside the guest (fstab entry + mount -a, via the guest agent — not SSH); a blkid check first skips mkfs if the disk already has a filesystem, so it's safe to populate a disk from outside the guest (e.g. a migration) before this role ever mounts it. iothread/discard/cache/ssd are passed straight to community.proxmox.proxmox_disk when set (all optional, left unset otherwise — no behavior change for a disk that doesn't use them); cache: none + discard: on + iothread: true + ssd: true is the recommended combination for database-grade workloads. |
virtiofs_mounts |
no | List of {id, host_path, guest_path} — shares a host directory into the guest via virtiofs (tag id), and mounts it at guest_path inside the VM (fstab entry + mount -a, via the guest agent — not SSH). |
firewall |
no | Containers: true sets the NIC's firewall=1 flag without firewall_ports, for rules managed outside this role (e.g. /etc/pve/firewall/<vmid>.fw). The rules then have to come from the caller. |
firewall_ports |
no | List of {port, proto} to open. See Firewall — the NIC's firewall=1 flag this implies is creation-only, same as the rest of the NIC config. |
proxmox_container fields
Same calling convention, via tasks_from: container and a proxmox_container: var.
| Field | Required | Description |
|---|---|---|
name |
yes | Hostname of the container |
node |
yes | Node key from proxmox_nodes |
state |
no | present (default) or absent — see Decommissioning |
vmid |
no | Proxmox VM ID; auto-assigned if omitted. If set, asserted cluster-wide against every other VM/container — fails fast if it's already assigned to a differently-named machine |
os_template |
yes | Storage-qualified template path, e.g. local:vztmpl/debian-13-standard_13.0-1_amd64.tar.zst |
password / ssh_key |
one | Root login. Both, pool, and unprivileged only apply at creation — ignored on update |
nics |
yes | List of NICs, same shape as VM NICs (net0, net1, ... in NIC order) |
cores/memory/swap |
no | Defaults: 2/2048/512 |
unprivileged |
no | Default true |
features |
no | List of Proxmox container features, e.g. ["nesting=1"]. Reconciled every run. Needed for systemd units inside the container that use mount-namespacing hardening (ProtectSystem=, ProtectHome=, PrivateTmp=, etc.) — without nesting=1 those fail at start with 226/NAMESPACE. See pct options. |
root_disk.size/.storage |
no | Default 8 GB |
nameserver |
no | |
pool |
no | Created automatically if it doesn't exist |
tags |
no | |
onboot |
no | Default true |
start_after_creation |
no | Default true; only applies the first time the container is created |
data_disks |
no | List of {mountpoint, size, storage} extra mounts |
firewall_ports |
no | List of {port, proto} to open. See Firewall — unlike VMs, the NIC's firewall=1 flag this implies is reconciled every run, not creation-only. |
Decommissioning
Call the same entry point with state: absent — force-stops the instance first if it's running:
- name: Decommission the database VM
ansible.builtin.include_role:
name: proxmox
tasks_from: vm
vars:
proxmox_vm:
name: db01
node: pve10
state: absent
Firewall
Set firewall_ports on a proxmox_vm/proxmox_container to open specific ports on it:
proxmox_vm:
...
firewall_ports:
- { port: 443, proto: tcp }
- { port: 80, proto: tcp }
This requires proxmox_firewall_management_cidrs to already be set (the role asserts on it — see below) and does three things: adds firewall=1 to the guest's NIC, creates ACCEPT rules for exactly the given ports, and enables the guest's own firewall (Proxmox's per-guest firewall is otherwise inert even with rules present). Everything else stays blocked.
Why proxmox_firewall_management_cidrs is required first: Proxmox's cluster-wide firewall switch has to be on for any guest-level firewall to do anything — there is no way to have a working per-VM firewall while leaving the cluster level fully untouched. Locking a VM down to just its app ports with nothing else allowed would also cut off SSH/Ansible access to that VM. So:
# group_vars/all/proxmox_firewall.yml
proxmox_firewall_management_cidrs:
- "10.13.37.0/24"
When set, the role's normal entry point (roles: [proxmox]) populates Proxmox's built-in cluster-level management IP set with these CIDRs (which Proxmox auto-generates SSH/API/GUI access rules from) and enables the cluster-wide firewall. Every VM/container with firewall_ports set then automatically gets an ACCEPT rule referencing that same IP set, so management access is never cut off by locking a machine down to its app ports. Node-level firewall config is left untouched (Proxmox enables it by default).
Leave proxmox_firewall_management_cidrs empty and nothing at cluster level is touched — firewall_ports on any VM/container then has no effect (the assert will tell you why).
Image and template acquisition
proxmox_vms_images/proxmox_lxc_templates are downloaded/fetched by this role's normal entry point (roles: [proxmox]), not by vm/container — run that once centrally (e.g. the regular host-setup play), not per service. Give each image/template a name via a shared variable so the acquisition list and every service's root_disk.image/os_template reference the same value instead of duplicating raw paths/URLs:
# group_vars/all/proxmox_images.yml
proxmox_image_debian13: /var/lib/vz/template/cloud-init/debian-13-generic-amd64.qcow2
proxmox_lxc_template_debian13: "local:vztmpl/debian-13-standard_13.0-1_amd64.tar.zst"
proxmox_vms_images:
- url: "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2"
path: "{{ proxmox_image_debian13 }}"
proxmox_lxc_templates:
- node: pve10
url: "http://download.proxmox.com/images/system/debian-13-standard_13.0-1_amd64.tar.zst"