--- - name: Build Dynamic Rocky Linux LXC Container hosts: localhost gather_facts: false vars: # --- Container Specifications --- lxc_hostname: "new_lxc" lxc_template: "local:vztmpl/rockylinux-9-default_20240912_amd64.tar.xz" lxc_cores: 2 lxc_memory: 1024 lxc_storage: "TB" lxc_disk_size: 10 lxc_bridge: "vmbr0" lxc_dns: "192.168.2.2" target_node: "pve" # --- Security & Access --- lxc_ssh_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINegitHaQG8i+s412h3wTWf/KvpeX1CEpYFva9MhHR+7 ansible-key" tasks: - name: Get the next available VMID from the Proxmox cluster ansible.builtin.uri: url: "https://{{ proxmox_api_host }}:8006/api2/json/cluster/nextid" method: GET headers: Authorization: "PVEAPIToken {{ proxmox_api_user }}={{ proxmox_api_password }}" validate_certs: false return_content: true register: nextid_response - name: Extract the dynamic VMID from the API response ansible.builtin.set_fact: dynamic_vmid: "{{ nextid_response.json.data }}" - name: Create the Rocky Linux LXC container community.general.proxmox: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_password: "{{ proxmox_api_password }}" node: "{{ target_node }}" vmid: "{{ dynamic_vmid }}" hostname: "{{ lxc_hostname }}" ostemplate: "{{ lxc_template }}" cores: "{{ lxc_cores }}" memory: "{{ lxc_memory }}" # FIX: Combined storage pool and size into the single required format disk: "{{ lxc_storage }}:{{ lxc_disk_size }}" # Configure network for DHCP on the specified bridge netif: '{"net0":"name=eth0,bridge={{ lxc_bridge }},ip=dhcp"}' # Explicitly set the DNS nameserver nameserver: "{{ lxc_dns }}" # Inject the SSH public key pubkey: "{{ lxc_ssh_key }}" # Highly recommended security flag for Proxmox containers unprivileged: true state: present - name: Ensure the new LXC container is powered on community.general.proxmox: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_password: "{{ proxmox_api_password }}" vmid: "{{ dynamic_vmid }}" state: started - name: Output the assigned VMID to the Semaphore UI logs ansible.builtin.debug: msg: "Successfully built {{ lxc_hostname }} (Rocky Linux 9) with dynamic ID: {{ dynamic_vmid }}"