feat(pve_vm): add the pve_vm role
Build / build (pull_request) Successful in 46s
Lint / lint (pull_request) Successful in 2m57s
Molecule / molecule (pull_request) Successful in 30m40s

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
This commit is contained in:
Defame1297 committed 2026-11-29 20:10:33 +00:00
1 parent 7f28fccfe4
commit f3cab37c7b
25 files changed
+1433 -7

No files matched your search

@@ -0,0 +1,24 @@
---
# One drift case: seeds the live VM config the REST lookup would return, runs the role's drift
# detection with the inputs the caller sets on the include, and asserts each expected drift fact.
# Input: pve_vm_test_case (name, config, expect: a mapping of drift dimension to true or false,
# needs_update for the combined result).
- name: "Seed the live VM config, case {{ pve_vm_test_case.name }}"
ansible.builtin.set_fact:
__pve_vm_config: "{{ pve_vm_test_case.config }}"
- name: "Detect configuration drift, case {{ pve_vm_test_case.name }}"
ansible.builtin.include_role:
name: mortis.kamino.pve_vm
tasks_from: detect_drift
- name: "Assert the drift facts, case {{ pve_vm_test_case.name }}"
ansible.builtin.assert:
that: (lookup('ansible.builtin.vars', pve_vm_test_fact) | bool) == (item.value | bool)
fail_msg: "{{ pve_vm_test_fact }} is {{ lookup('ansible.builtin.vars', pve_vm_test_fact) }}, expected {{ item.value }}"
quiet: true
vars:
pve_vm_test_fact: "{{ '__pve_vm_needs_update' if item.key == 'needs_update' else '__pve_vm_drift_' ~ item.key }}"
loop: "{{ pve_vm_test_case.expect | dict2items }}"
loop_control:
label: "{{ item.key }}"
@@ -0,0 +1,22 @@
---
# One failing run: includes the role's task file named by the case, with the inputs the caller
# sets on the include, and asserts that the expected message, not something else, stopped it.
# Input: pve_vm_test_case (name, tasks_from, expect).
- name: "Run the role, case {{ pve_vm_test_case.name }}"
block:
- name: "Include the role, case {{ pve_vm_test_case.name }}"
ansible.builtin.include_role:
name: mortis.kamino.pve_vm
tasks_from: "{{ pve_vm_test_case.tasks_from }}"
# Only reached when the include returned. The message must not contain the expected
# text, so the rescue below cannot mistake it for the failure under test.
- name: "Fail because the include returned, case {{ pve_vm_test_case.name }}"
ansible.builtin.fail:
msg: The role accepted the input
rescue:
- name: "The expected failure stopped the run, case {{ pve_vm_test_case.name }}"
ansible.builtin.assert:
that: pve_vm_test_case.expect in (ansible_failed_result.msg | default(''))
fail_msg: "Expected '{{ pve_vm_test_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
quiet: true
@@ -0,0 +1,15 @@
---
# One level of the static check's flattening: moves the pending tasks into pve_vm_test_tasks and
# makes their block, rescue and always lists the next pending ones, then recurses until none is left.
# Both facts are templated from the values before this task.
- name: Flatten one level of blocks
ansible.builtin.set_fact:
pve_vm_test_tasks: "{{ [pve_vm_test_tasks, pve_vm_test_pending] | flatten(levels=1) }}"
pve_vm_test_pending: >-
{{ [pve_vm_test_pending | map(attribute='block', default=[]) | list,
pve_vm_test_pending | map(attribute='rescue', default=[]) | list,
pve_vm_test_pending | map(attribute='always', default=[]) | list] | flatten(levels=2) }}
- name: Flatten the next level
ansible.builtin.include_tasks: flatten_tasks.yml
when: pve_vm_test_pending | length > 0