--- # Creates a Rocky Linux 9 container through the Proxmox API and starts it. # Runs on the Semaphore host (localhost); proxmoxer must be importable by the # Python that runs Ansible there. # # Extra vars (Semaphore environment / variable group): # proxmox_api_user - e.g. root@pam (required) # proxmox_api_password - that user's password (this, or a token) # proxmox_api_token_id / proxmox_api_token_secret (API token instead of a password) # proxmox_api_host - defaults to the pve entry in the inventory # # Optional: lxc_hostname, lxc_template, lxc_cores, lxc_memory, lxc_storage, # lxc_disk_size, lxc_bridge, lxc_dns, target_node. - name: Build a Rocky Linux LXC container hosts: localhost connection: local gather_facts: false vars: proxmox_api_host: "{{ hostvars['pve'].ansible_host }}" target_node: mini-pc lxc_hostname: new-lxc # underscores are not valid in a hostname 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: "{{ hostvars['pihole'].ansible_host }}" lxc_ssh_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINegitHaQG8i+s412h3wTWf/KvpeX1CEpYFva9MhHR+7 ansible-key" module_defaults: community.proxmox.proxmox: api_host: "{{ proxmox_api_host }}" api_user: "{{ proxmox_api_user }}" api_password: "{{ proxmox_api_password | default(omit) }}" api_token_id: "{{ proxmox_api_token_id | default(omit) }}" api_token_secret: "{{ proxmox_api_token_secret | default(omit) }}" validate_certs: false timeout: 300 # template extraction takes longer than the 30 s default tasks: - name: Ensure proxmoxer is available to the controller's Python ansible.builtin.command: "{{ ansible_playbook_python }} -m pip install proxmoxer requests" register: pip_install changed_when: "'Successfully installed' in pip_install.stdout" - name: Create the container (Proxmox assigns the next free VMID) community.proxmox.proxmox: node: "{{ target_node }}" hostname: "{{ lxc_hostname }}" ostemplate: "{{ lxc_template }}" cores: "{{ lxc_cores }}" memory: "{{ lxc_memory }}" disk: "{{ lxc_storage }}:{{ lxc_disk_size }}" netif: net0: "name=eth0,bridge={{ lxc_bridge }},ip=dhcp" nameserver: "{{ lxc_dns }}" pubkey: "{{ lxc_ssh_key }}" unprivileged: true state: present register: lxc_create - name: Start the container community.proxmox.proxmox: vmid: "{{ lxc_create.vmid }}" state: started - name: Report ansible.builtin.debug: msg: >- Built {{ lxc_hostname }} (Rocky Linux 9) as VMID {{ lxc_create.vmid }} on {{ target_node }}. Next: run discover_guests.yml with adopt=true, add it to inventories/all.yml, then bootstrap_lxc.yml.