qemu agent for vm template
This commit is contained in:
parent
e03c21e853
commit
102fad268c
1 changed files with 49 additions and 2 deletions
|
|
@ -26,6 +26,9 @@
|
|||
proxmox_sshkey_path: "/home/{{ new_user }}/.ssh/authorized_keys" # Path to pubkey file for cloud-init injection
|
||||
proxmox_ci_upgrade: true # If true, run package upgrade on first boot
|
||||
|
||||
# Auto-install qemu-guest-agent in clones via cloud-init snippet
|
||||
qemu_agent_snippet_filename: "user-data-qemu-agent.yaml"
|
||||
|
||||
# Storage to import disk into; use existing storage like local-lvm or your ZFS pool name
|
||||
proxmox_image_storage: "{{ zfs_pool_name }}"
|
||||
|
||||
|
|
@ -57,6 +60,34 @@
|
|||
force: false
|
||||
when: not debian_image_stat.stat.exists
|
||||
|
||||
- name: Ensure ZFS storage allows snippets content
|
||||
command: >
|
||||
pvesm set {{ proxmox_image_storage }} --content images,rootdir,snippets
|
||||
|
||||
- name: Ensure local storage allows snippets content
|
||||
command: >
|
||||
pvesm set local --content images,iso,vztmpl,snippets
|
||||
failed_when: false
|
||||
|
||||
- name: Ensure snippets directory exists on storage mountpoint
|
||||
file:
|
||||
path: "{{ zfs_pool_mountpoint }}/snippets"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Write cloud-init user-data snippet to install qemu-guest-agent
|
||||
copy:
|
||||
dest: "{{ zfs_pool_mountpoint }}/snippets/{{ qemu_agent_snippet_filename }}"
|
||||
mode: '0644'
|
||||
content: |
|
||||
#cloud-config
|
||||
package_update: false
|
||||
package_upgrade: false
|
||||
packages:
|
||||
- qemu-guest-agent
|
||||
runcmd:
|
||||
- [ systemctl, enable, --now, qemu-guest-agent ]
|
||||
|
||||
- name: Check if VMID already exists
|
||||
command: qm config {{ proxmox_template_vmid }}
|
||||
register: vmid_config_check
|
||||
|
|
@ -91,6 +122,21 @@
|
|||
when:
|
||||
- vmid_config_check.rc != 0 or not vm_already_template
|
||||
|
||||
- name: Check if ide2 (cloudinit) drive exists
|
||||
command: qm config {{ proxmox_template_vmid }}
|
||||
register: vm_config_check
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
when:
|
||||
- vmid_config_check.rc == 0
|
||||
|
||||
- name: Remove existing ide2 (cloudinit) drive if it exists for idempotency
|
||||
command: >
|
||||
qm set {{ proxmox_template_vmid }} --delete ide2
|
||||
when:
|
||||
- vmid_config_check.rc == 0
|
||||
- "'ide2:' in vm_config_check.stdout"
|
||||
|
||||
- name: Build consolidated qm set argument list (simplified)
|
||||
set_fact:
|
||||
qm_set_args: >-
|
||||
|
|
@ -110,15 +156,16 @@
|
|||
]
|
||||
+ (proxmox_ci_upgrade | bool
|
||||
| ternary(['--ciupgrade 1'], []))
|
||||
+ ['--cicustom user=local:snippets/' ~ qemu_agent_snippet_filename]
|
||||
}}
|
||||
when:
|
||||
- vmid_config_check.rc != 0 or not vm_already_template
|
||||
- vmid_config_check.rc != 0 or not vm_already_template | default(false)
|
||||
|
||||
- name: Apply consolidated qm set
|
||||
command: >
|
||||
qm set {{ proxmox_template_vmid }} {{ qm_set_args | join(' ') }}
|
||||
when:
|
||||
- vmid_config_check.rc != 0 or not vm_already_template
|
||||
- vmid_config_check.rc != 0 or not vm_already_template | default(false)
|
||||
|
||||
- name: Resize primary disk to requested size
|
||||
command: >
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue