AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible on Proxmox VE 8 Automation Complete Guide

By Luca Berton · Published 2024-01-01 · Category: installation

Automate Proxmox VE 8 with Ansible: community.general.proxmox modules, KVM/LXC, clusters, storage, backups, dynamic inventory.

Proxmox VE 8 (latest 8.4) is the open-source enterprise hypervisor combining KVM and LXC on a Debian 12 base. Ansible automates the cluster, nodes, VMs, containers, and storage via the community.general proxmox modules and the Proxmox API. This is the master Ansible guide for Proxmox VE 8.

Proxmox VE 8 release facts

| Item | Value | |---|---| | Base OS | Debian 12 Bookworm | | Kernel | 6.8 / 6.11 | | QEMU | 9.x | | LXC | 6.x | | Latest | 8.4 | | API | Proxmox REST API (port 8006) |

See also: Ansible for Proxmox: Automate VM and Container Management Complete Guide

Ansible-core compatibility

Use ansible-core 2.18 LTS. Required Python on the control node:

pip install proxmoxer requests

Collections:

collections:
  - name: community.general
    version: ">=10.0.0"

Inventory

[pve]
pve01 ansible_host=10.0.0.11
pve02 ansible_host=10.0.0.12
pve03 ansible_host=10.0.0.13

[pve:vars] proxmox_api_host=pve01.lab.example.com proxmox_api_user=automation@pve proxmox_api_token_id=ansible proxmox_api_token_secret='{{ vault_pve_token }}'

See also: How to Add a Disk to a VMware VM Using Ansible Playbook

Create a KVM VM

- name: Create KVM VM on Proxmox
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Create VM
      community.general.proxmox_kvm:
        api_host: "{{ proxmox_api_host }}"
        api_user: "{{ proxmox_api_user }}"
        api_token_id: "{{ proxmox_api_token_id }}"
        api_token_secret: "{{ proxmox_api_token_secret }}"
        validate_certs: false
        node: pve01
        name: app-01
        vmid: 110
        cores: 4
        memory: 8192
        net:
          net0: "virtio,bridge=vmbr0,tag=100"
        scsihw: virtio-scsi-pci
        scsi:
          scsi0: "local-lvm:32"
        ide:
          ide2: "local:iso/ubuntu-24.04.iso,media=cdrom"
        ostype: l26
        state: present

- name: Start VM community.general.proxmox_kvm: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" validate_certs: false node: pve01 name: app-01 state: started

LXC container

- name: Create LXC on Proxmox
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Create container
      community.general.proxmox:
        api_host: "{{ proxmox_api_host }}"
        api_user: "{{ proxmox_api_user }}"
        api_token_id: "{{ proxmox_api_token_id }}"
        api_token_secret: "{{ proxmox_api_token_secret }}"
        validate_certs: false
        node: pve02
        hostname: ct-runner-01
        ostemplate: "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
        cores: 2
        memory: 1024
        swap: 512
        disk: "local-lvm:8"
        netif:
          net0: "name=eth0,bridge=vmbr0,ip=dhcp"
        password: "{{ vault_ct_password }}"
        state: present

- name: Start container community.general.proxmox: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_token_id: "{{ proxmox_api_token_id }}" api_token_secret: "{{ proxmox_api_token_secret }}" validate_certs: false node: pve02 hostname: ct-runner-01 state: started

See also: Configure Ansible Dynamic Inventory for VMware in Simple Steps

Backup jobs

- name: Create backup job
  hosts: localhost
  gather_facts: false
  tasks:
    - name: vzdump backup
      community.general.proxmox_backup:
        api_host: "{{ proxmox_api_host }}"
        api_user: "{{ proxmox_api_user }}"
        api_token_id: "{{ proxmox_api_token_id }}"
        api_token_secret: "{{ proxmox_api_token_secret }}"
        validate_certs: false
        node: pve01
        vmid: 110
        storage: pbs01
        mode: snapshot
        compress: zstd
        state: present

Dynamic inventory

Use community.general.proxmox inventory plugin:

# inventory.proxmox.yml
plugin: community.general.proxmox
url: https://pve01.lab.example.com:8006
user: automation@pve
token_id: ansible
token_secret: "{{ lookup('ansible.builtin.env', 'PROXMOX_TOKEN') }}"
validate_certs: false
want_facts: true

Best practices

• Use API tokens with role-based privileges, not root passwords. • Run config-management tasks inside guests via SSH; keep Proxmox API tasks for hypervisor-layer ops. • Pair Ansible with Proxmox Backup Server (PBS) for daily incrementals. • Keep vmid numbering deterministic (e.g., per-environment block) and managed in inventory variables.

Conclusion

Proxmox VE 8 + community.general.proxmox modules give you a fully API-driven open-source hypervisor stack. Use API tokens, dynamic inventory, and the KVM/LXC/backup module trio to manage Proxmox clusters at scale.

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home