--- - name: Download cloud-init image register: image ansible.builtin.get_url: url: "{{ image_url }}" dest: /tmp mode: '0644' force: true - name: Install pip ansible.builtin.apt: name: - pip update_cache: true install_recommends: false state: present - name: Install proxmoxer ansible.builtin.pip: name: proxmoxer state: present - name: Create new VM template from cloud-init image community.general.proxmox_kvm: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_password: "{{ api_password }}" node: "{{ node_target }}" name: "{{ template_name }}" bios: ovmf boot: 'order=scsi0' cores: 1 sockets: 1 machine: q35 memory: 4096 ostype: "{{ image_ostype }}" efidisk0: storage: "{{ storage_target }}" format: raw efitype: 4m pre_enrolled_keys: 1 serial: serial0: 'socket' vga: serial0 scsihw: 'virtio-scsi-single' scsi: scsi0: "{{ storage_target }}:0,iothread=1,discard=on,import-from={{ image.dest }},format=raw" ide: ide2: "{{ storage_target }}:cloudinit,format=raw" net: net0: 'virtio,bridge=vmbr0,firewall=1' template: true - name: Clone {{ item.name }} VM from cloud-init template register: vm_result community.general.proxmox_kvm: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" name: "{{ item.name }}" node: "{{ node_target }}" clone: "{{ template_name }}" storage: "{{ storage_target }}" - name: Grow {{ item.name }} VM disk community.general.proxmox_disk: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" vmid: "{{ vm_result.vmid }}" disk: scsi0 size: "{{ item.size }}" state: resized - name: Update {{ item.name }} VM configuration vars: ssh_key_path: "{{ lookup('env', 'HOME') }}/.ssh/id_rsa.pub" community.general.proxmox_kvm: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" node: "{{ node_target }}" vmid: "{{ vm_result.vmid }}" agent: 1 cores: "{{ item.cores }}" memory: "{{ item.memory }}" ciuser: "{{ ci_user }}" cipassword: "{{ ci_password }}" ipconfig: ipconfig0: 'ip=dhcp' sshkeys: "{{ lookup('ansible.builtin.file', '{{ ssh_key_path }}') }}" update: true - name: Start {{ item.name }} VM community.general.proxmox_kvm: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" node: "{{ node_target }}" vmid: "{{ vm_result.vmid }}" state: started - name: Prompt for {{ item.name }} VM host register: target_host_result ansible.builtin.pause: prompt: "Enter host/IP for {{ item.name }} VM" - name: Add {{ item.name }} VM host ansible.builtin.add_host: name: "{{ target_host_result.user_input }}" groups: "{{ item.name }}" ansible_user: "{{ ci_user }}" - name: Install qemu guest agent on {{ item.name }} VM delegate_to: "{{ target_host_result.user_input }}" delegate_facts: true become: yes ansible.builtin.package: name: qemu-guest-agent state: present update_cache: true install_recommends: false - name: Restart qemu guest agent on {{ item.name }} VM delegate_to: "{{ target_host_result.user_input }}" delegate_facts: true become: yes ansible.builtin.service: name: qemu-guest-agent state: restarted