qemu works

This commit is contained in:
counterweight 2025-10-31 00:17:42 +01:00
parent 102fad268c
commit 6f42e43efb
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -39,8 +39,6 @@
changed_when: false changed_when: false
failed_when: pve_version_check.rc != 0 failed_when: pve_version_check.rc != 0
- name: Ensure destination directory exists for cloud image - name: Ensure destination directory exists for cloud image
file: file:
path: "{{ debian_cloud_image_dest_dir }}" path: "{{ debian_cloud_image_dest_dir }}"
@ -75,18 +73,31 @@
state: directory state: directory
mode: '0755' mode: '0755'
- name: Read SSH public key content
slurp:
src: "{{ proxmox_sshkey_path }}"
register: ssh_key_content
- name: Extract SSH keys from authorized_keys file
set_fact:
ssh_keys_list: "{{ ssh_key_content.content | b64decode | split('\n') | select('match', '^ssh-') | list }}"
- name: Write cloud-init user-data snippet to install qemu-guest-agent - name: Write cloud-init user-data snippet to install qemu-guest-agent
copy: copy:
dest: "{{ zfs_pool_mountpoint }}/snippets/{{ qemu_agent_snippet_filename }}" dest: "{{ zfs_pool_mountpoint }}/snippets/{{ qemu_agent_snippet_filename }}"
mode: '0644' mode: '0644'
content: | content: |
#cloud-config #cloud-config
package_update: false user: {{ proxmox_ciuser }}
package_upgrade: false ssh_authorized_keys:
{{ ssh_keys_list | to_nice_yaml | indent(10, first=True) }}
package_update: true
package_upgrade: true
packages: packages:
- qemu-guest-agent - qemu-guest-agent
runcmd: runcmd:
- [ systemctl, enable, --now, qemu-guest-agent ] - systemctl enable qemu-guest-agent
- systemctl start qemu-guest-agent
- name: Check if VMID already exists - name: Check if VMID already exists
command: qm config {{ proxmox_template_vmid }} command: qm config {{ proxmox_template_vmid }}
@ -133,6 +144,7 @@
- name: Remove existing ide2 (cloudinit) drive if it exists for idempotency - name: Remove existing ide2 (cloudinit) drive if it exists for idempotency
command: > command: >
qm set {{ proxmox_template_vmid }} --delete ide2 qm set {{ proxmox_template_vmid }} --delete ide2
register: ide2_removed
when: when:
- vmid_config_check.rc == 0 - vmid_config_check.rc == 0
- "'ide2:' in vm_config_check.stdout" - "'ide2:' in vm_config_check.stdout"
@ -159,13 +171,13 @@
+ ['--cicustom user=local:snippets/' ~ qemu_agent_snippet_filename] + ['--cicustom user=local:snippets/' ~ qemu_agent_snippet_filename]
}} }}
when: when:
- vmid_config_check.rc != 0 or not vm_already_template | default(false) - vmid_config_check.rc != 0 or not vm_already_template | default(false) or ide2_removed.changed | default(false)
- name: Apply consolidated qm set - name: Apply consolidated qm set
command: > command: >
qm set {{ proxmox_template_vmid }} {{ qm_set_args | join(' ') }} qm set {{ proxmox_template_vmid }} {{ qm_set_args | join(' ') }}
when: when:
- vmid_config_check.rc != 0 or not vm_already_template | default(false) - vmid_config_check.rc != 0 or not vm_already_template | default(false) or ide2_removed.changed | default(false)
- name: Resize primary disk to requested size - name: Resize primary disk to requested size
command: > command: >
@ -177,13 +189,3 @@
command: qm template {{ proxmox_template_vmid }} command: qm template {{ proxmox_template_vmid }}
when: when:
- vmid_config_check.rc == 0 and not vm_already_template or vmid_config_check.rc != 0 - vmid_config_check.rc == 0 and not vm_already_template or vmid_config_check.rc != 0
- name: Show resulting template configuration
command: qm config {{ proxmox_template_vmid }}
register: final_template_config
changed_when: false
- name: Debug final template config
debug:
msg: "{{ final_template_config.stdout }}"