Files
ansible/roles/proxmox/README.md
2025-09-07 21:40:21 +02:00

2.8 KiB

Proxmox Ansible Role

This role facilitates the management of Proxmox VE resources, including virtual machines (VMs) and LXC containers. It automates the setup of Proxmox nodes and the creation, configuration, and destruction of guests.

Role Variables

Variable Description Default Value
proxmox_author The author of the Proxmox resources. tuan-dat.tran@tudattr.dev
proxmox_creator The creator of the Proxmox resources. ansible
proxmox_storage The Proxmox storage to use. proxmox
proxmox_vault_file The path to the vault file for storing secrets. ../vars/group_vars/proxmox/secrets_vm.yml
proxmox_secrets_prefix The prefix for secrets stored in the vault. secrets_vm
proxmox_cloud_init_images A dictionary of cloud-init images to download. { 'debian': { 'name': 'debian-12-genericcloud-amd64.qcow2', 'url': '...' }, 'ubuntu': { 'name': 'noble-server-cloudimg-amd64.img', 'url': '...' } }
proxmox_dirs A dictionary of directories used by the role. { 'isos': '/opt/proxmox/template/iso/' }
proxmox_tags A list of tags to apply to the Proxmox resources. ['{{ proxmox_creator }}']
proxmox_node_dependencies A list of dependencies to install on the Proxmox node. ['nmap']
proxmox_localhost_dependencies A list of dependencies to install on the localhost. []
vms A list of VMs to create. [{ 'name': 'test-vm', 'vmid': 1000, ... }]
lxcs A list of LXC containers to create. [{ 'name': 'test-lxc', 'vmid': 2000, ... }]

Handlers

  • Reboot Node: Reboots the Proxmox node. This is triggered when the GRUB configuration or VFIO modules are changed.

Tasks

The role includes the following main tasks:

  • 00_setup_machines.yml: Prepares the localhost and Proxmox nodes by installing dependencies and configuring hardware acceleration.
  • 10_create_secrets.yml: Creates a vault file and generates secrets for the VMs.
  • 40_prepare_vm_creation.yml: Downloads cloud-init images required for VM creation.
  • 50_create_vms.yml: Creates VMs based on the vms variable.
  • 60_create_containers.yml: Creates LXC containers based on the lxcs variable.

Usage

Here is an example of how to use this role in a playbook:

- hosts: proxmox
  roles:
    - role: proxmox
      vars:
        proxmox_api_user: "root@pam"
        proxmox_api_token_id: "your-token-id"
        proxmox_api_token_secret: "your-token-secret"
        proxmox_api_host: "your-proxmox-host"
        vms:
          - name: my-vm
            vmid: 1001
            node: proxmox
            cores: 4
            memory: 8192
            disk_size: 50
            boot_image: debian-12-genericcloud-amd64.img
            ciuser: myuser
            sshkeys: "your-ssh-key"
            net:
              net0: "virtio=BC:24:11:7E:2B:A1,bridge=vmbr0"