--- - name: download template command: "pveam download local {{ flavors[proxmox.flavor].template }}_amd64.tar.xz" args: creates: "/var/lib/vz/template/cache/{{ flavors[proxmox.flavor].template }}_amd64.tar.xz" delegate_to: "{{ proxmox.host }}" - name: create host command: > pct create {{ proxmox.id }} "/var/lib/vz/template/cache/{{ flavors[proxmox.flavor].template }}_amd64.tar.xz" --hostname {{ inventory_hostname }} --storage local-zfs -net0 name=eth0,bridge=vmbr0,ip=dhcp -onboot 1 {% if not proxmox.privileged|default(false) %} -unprivileged {% endif %} {% if proxmox.features|default(None) %} -features {{ proxmox.features }} {% endif %} -memory {{ proxmox.memory|default(1024) }} {% for disk in proxmox.disks|default([]) %} --mp{{ disk.index }} volume={{ disk.storage }}:{{ disk.size_gb }},mp={{ disk.path }} {% endfor %} -rootfs local-zfs:{{ proxmox.disk|default(4) }} --password {{ ansible_password|trim }} --nameserver {{ hostvars[proxmox.host].network.self_internal_ip }} --ostype {{ flavors[proxmox.flavor].pct_ostype }} args: creates: "/etc/pve/lxc/{{ proxmox.id }}.conf" delegate_to: "{{ proxmox.host }}" - name: allow backups shell: "zfs allow -u backups mount,send,hold,snapshot,destroy rpool/data/$(pct config {{ proxmox.id }} | grep mp{{ item.index }} | cut -d , -f 1 | cut -d : -f 3)" delegate_to: "{{ proxmox.host }}" loop: "{{ proxmox.disks|default([]) }}" - name: proxmox extra when: proxmox.extra|default(None) block: - name: set proxmox extra copy out copy: remote_src: yes src: /etc/pve/lxc/{{ proxmox.id }}.conf dest: /tmp/{{ proxmox.id }}.conf delegate_to: "{{ proxmox.host }}" - name: read conf slurp: src: /tmp/{{ proxmox.id }}.conf register: proxmox_conf delegate_to: "{{ proxmox.host }}" - name: set proxmox extra lineinfile: path: /tmp/{{ proxmox.id }}.conf line: "{{ item }}" loop: "{{ proxmox.extra }}" delegate_to: "{{ proxmox.host }}" - name: set proxmox extra copy in command: cp /tmp/{{ proxmox.id }}.conf /etc/pve/lxc/{{ proxmox.id }}.conf delegate_to: "{{ proxmox.host }}" - name: start host shell: "{ pct status {{ proxmox.id }} | grep running ; } || pct start {{ proxmox.id }}" delegate_to: "{{ proxmox.host }}" - name: update packages to prevent automatic updates causing issues later. retry until network available command: pct exec {{ proxmox.id }} -- dnf update -y retries: 10 delay: 1 until: result.rc == 0 register: result delegate_to: "{{ proxmox.host }}" - name: install ssh command: pct exec {{ proxmox.id }} -- dnf install -y openssh-server delegate_to: "{{ proxmox.host }}" - name: permit root password lineinfile: path: /rpool/data/subvol-{{ proxmox.id }}-disk-0/etc/ssh/sshd_config regexp: "^#?PermitRootLogin" line: "PermitRootLogin yes" delegate_to: "{{ proxmox.host }}" - name: enable ssh command: pct exec {{ proxmox.id }} -- systemctl enable --now sshd delegate_to: "{{ proxmox.host }}"