Manage a Proxmox VE QEMU VM through the Proxmox API: clone from a template, cloud-init user, SSH keys and network, update only on detected drift, grow the boot disk, apply the power state, wait for SSH and cloud-init, and delete behind pve_vm_allow_destroy. The role never sets a cloud-init password and deletes a stored one with no_log. Inputs are validated first under the always tag: the API credentials, and pve_vm_disk_size while the disk is managed; the clone asserts pve_vm_clone_vmid. Only pve_vm_exists is public, every other fact and register is __pve_vm_. The molecule scenario runs offline on noble and resolute: validation with positive and refusal cases, drift detection over seeded VM configs, and static checks over the role's task files that no proxmox_kvm task or module_defaults entry carries cipassword and that the one task deleting a stored cipassword is no_log. The API lifecycle and the cloud-init wait are not exercised. README Roadmap: the pve_vm wave 2 line and the opnsense and proxmox_firewall line are removed; wave 3 stays. Closes #482 Assisted-by: Claude Code:claude-opus-5-5
48 lines
1.8 KiB
YAML
48 lines
1.8 KiB
YAML
---
|
|
- name: Get current VM config via REST API
|
|
no_log: true # Authorization header carries the API token
|
|
delegate_to: localhost
|
|
ansible.builtin.uri:
|
|
url: "https://{{ pve_vm_api_host }}:8006/api2/json/nodes/{{ pve_vm_node }}/qemu/{{ pve_vm_vmid }}/config"
|
|
method: GET
|
|
headers:
|
|
Authorization: "{{ __pve_vm_api_auth_header }}"
|
|
register: __pve_vm_current_config
|
|
# uri has no check mode support; this is a GET, so it also runs under --check and drift
|
|
# detection sees the live config.
|
|
check_mode: false
|
|
|
|
- name: Set fact to the actual config dict
|
|
no_log: true # the config may hold a stored cipassword (update.yml deletes it)
|
|
ansible.builtin.set_fact:
|
|
__pve_vm_config: "{{ __pve_vm_current_config.json.data }}"
|
|
|
|
- name: Extract current disk string
|
|
ansible.builtin.set_fact:
|
|
__pve_vm_disk_string: "{{ __pve_vm_config[pve_vm_boot_disk] | default('') }}"
|
|
|
|
- name: Extract current disk number and unit properly
|
|
ansible.builtin.set_fact:
|
|
__pve_vm_disk_parts: "{{ __pve_vm_disk_string | regex_findall('size=(\\d+)([GM])') | first | default(['0', 'G']) | list }}"
|
|
|
|
- name: Extract current disk number
|
|
ansible.builtin.set_fact:
|
|
__pve_vm_current_disk_size_number: "{{ __pve_vm_disk_parts[0] | int }}"
|
|
__pve_vm_current_disk_size_unit: "{{ __pve_vm_disk_parts[1] }}"
|
|
|
|
- name: Convert disk size to GB
|
|
ansible.builtin.set_fact:
|
|
__pve_vm_current_disk: >-
|
|
{{
|
|
__pve_vm_current_disk_size_number if __pve_vm_current_disk_size_unit == 'G'
|
|
else (__pve_vm_current_disk_size_number / 1024)
|
|
}}
|
|
|
|
- name: Determine if disk resize is needed
|
|
ansible.builtin.set_fact:
|
|
__pve_vm_resize_disk: "{{ pve_vm_disk_size | regex_replace('[^0-9]', '') | int > __pve_vm_current_disk | int }}"
|
|
when:
|
|
- pve_vm_manage_disk | bool
|
|
- pve_vm_disk_size is defined
|
|
- pve_vm_exists
|