feat(pve_vm): add the pve_vm role #489

Merged
Defame1297 merged 2 commits from feat/482-pve-vm-role into main 2026-12-01 20:56:45 +00:00
Owner

What and why

Adds the pve_vm role. It manages a Proxmox VE QEMU VM through the Proxmox API (community.proxmox):

  • it clones the VM from a template;
  • it sets the cloud-init user, SSH keys and network;
  • it updates an existing VM only on detected drift;
  • it grows the boot disk;
  • it applies the power state and waits for SSH and cloud-init;
  • it deletes the VM only when pve_vm_allow_destroy is true.

The role never sets a cloud-init password (cipassword). On a real run it deletes one stored on the VM, with no_log. The declared platforms are the guests, Ubuntu noble and resolute.

Closes #482

Amendment to the acceptance criterion on the Roadmap (maintainer, 2026-11-29): the README Roadmap section stays, because wave 3 (rke2, proxmox_host) is still to come. Only two lines are removed:

  • the pve_vm wave 2 line;
  • the "Later" line with opnsense and proxmox_firewall, which are not in any planned wave.

The "will not be extracted" text is unchanged. The role lists in the README intro and status line and in galaxy.yml now include pve_vm.

Changes compared with a plain port of the role:

  • Input checks are in tasks/validate.yml, imported first with tags: always. A tag-filtered run therefore also needs pve_vm_api_user and pve_vm_api_token_secret, and pve_vm_disk_size while pve_vm_manage_disk is true. The changelog fragment says so.
  • pve_vm_node and pve_vm_vmid are required: true in the argument spec. There is no legacy-name guard.
  • pve_vm_api_token_secret has no default. It is asserted set and non-empty on every run, since every run calls the API.
  • pve_vm_reboot_if_required (default true) and pve_vm_autostart (default true) have role defaults and spec entries. Before, both were read as | default(true).
  • New assert: pve_vm_disk_size must be set while pve_vm_manage_disk is true, unless the state is absent. It runs in validation, before any change.
  • New assert in tasks/create.yml, before the clone: pve_vm_clone_vmid must be set. It lives there because whether a clone happens is known only after the API lookup.
  • Only pve_vm_exists is a public fact. Every other fact, every registered result and the API auth header are now __pve_vm_*. That covers the former pve_vm_needs_update, pve_vm_config, pve_vm_created, pve_vm_disk_resized and the drift facts.
  • pve_vm_api_host still defaults to the ansible_host of pve_vm_node from hostvars. The README says to set it explicitly when the node is not an inventory host.
  • Otherwise behaviour is unchanged: drift detection, the --check previews and the stored-cipassword delete work as before.

Content scrub. I ran this grep over the role, excluding molecule:

grep -rnEi 'rke2|clotho|lachesis|atropos|moirai|devops|homelab|home lab|rkdr|defame|kamino-runner|gitea-runner|hosts/|host_vars|group_vars|#[0-9]+|([0-9]{1,3}\.){3}[0-9]{1,3}' roles/pve_vm --exclude-dir=molecule

Result:

roles/pve_vm/meta/main.yml:5:  author: Defame1297
roles/pve_vm/README.md:94:          ipconfig0: "ip={{ ansible_host }}/24,gw=192.0.2.1"

Both hits are expected. The first is the Collection author, as in every role's meta/main.yml. The second is a documentation address (TEST-NET-1). I also searched the whole added diff, scenario included, for names of the source environment, inventory paths and private addresses. The only hits were the repository's own molecule run label and molecule's group_vars: key, the same as in pve_lxc.

Verified

The scenario playbooks ran locally as plays against a local connection, not in a container:

  • Converge passed, both normally and under --check.
  • Verify passed:
    • 7 refusal cases, each matching its expected message;
    • 2 positive validation cases;
    • 12 drift cases;
    • the three static assertions, which found all 8 proxmox_kvm tasks, including one inside a block.

Mutation tests ran on scratch copies of the task files. Each mutation made the matching static assertion fail, and an unmutated copy passed:

  • cipassword in the module_defaults of the proxmox_kvm entry, and in a group/community.proxmox.proxmox entry;
  • a task file in a subdirectory, with a task two blocks deep under the short name proxmox_kvm and cipassword under args:;
  • an action: mapping with module: community.proxmox.proxmox_kvm;
  • a local_action: string proxmox_kvm vmid=1 cipassword=x;
  • the key ansible.legacy.proxmox_kvm;
  • a second, non-no_log task deleting cipassword through an action: mapping;
  • a harmless action: task, which passed as it should.

Other checks:

  • ansible-doc -t role mortis.kamino.pve_vm renders the spec.
  • python3 -m unittest discover -s tests/scripts: 304 tests OK.
  • The commit-stage pre-commit hooks passed, including ansible-lint, yamllint, REUSE, gitleaks and the changelog fragment lint.
  • scripts/select_molecule_scenarios.py selects roles/pve_vm/molecule/default.
  • The pre-push ansible-test sanity passed.

CI on f3cab37 is all green: build run 6777, lint run 6778 and molecule run 6779. In run 6779 the pve_vm/default scenario finished with exit 0 after 40 s. Its duration entry in scripts/run_molecule_scenarios.sh stays at the estimate of 60 s, since the entry only orders the scenarios.

Not verified

  • The API lifecycle is not exercised by molecule: lookup, clone, update, the stored-cipassword delete, resize, start, stop, restart and delete. There is no Proxmox API in the scenario.
  • The guest-side cloud-init wait (cloud-init status --wait) is untested on both releases, because the test images do not ship cloud-init.
  • The listed API privileges and the token privilege-separation note in the README come from the Proxmox documentation and the role's calls. They were not tested against a live node.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code:claude-opus-5-5

🤖 Generated with Claude Code

## What and why Adds the `pve_vm` role. It manages a Proxmox VE QEMU VM through the Proxmox API (`community.proxmox`): - it clones the VM from a template; - it sets the cloud-init user, SSH keys and network; - it updates an existing VM only on detected drift; - it grows the boot disk; - it applies the power state and waits for SSH and cloud-init; - it deletes the VM only when `pve_vm_allow_destroy` is true. The role never sets a cloud-init password (`cipassword`). On a real run it deletes one stored on the VM, with `no_log`. The declared platforms are the guests, Ubuntu noble and resolute. Closes #482 **Amendment to the acceptance criterion on the Roadmap (maintainer, 2026-11-29):** the README Roadmap section stays, because wave 3 (`rke2`, `proxmox_host`) is still to come. Only two lines are removed: - the `pve_vm` wave 2 line; - the "Later" line with `opnsense` and `proxmox_firewall`, which are not in any planned wave. The "will not be extracted" text is unchanged. The role lists in the README intro and status line and in `galaxy.yml` now include `pve_vm`. **Changes compared with a plain port of the role:** - Input checks are in `tasks/validate.yml`, imported first with `tags: always`. A tag-filtered run therefore also needs `pve_vm_api_user` and `pve_vm_api_token_secret`, and `pve_vm_disk_size` while `pve_vm_manage_disk` is true. The changelog fragment says so. - `pve_vm_node` and `pve_vm_vmid` are `required: true` in the argument spec. There is no legacy-name guard. - `pve_vm_api_token_secret` has no default. It is asserted set and non-empty on every run, since every run calls the API. - `pve_vm_reboot_if_required` (default `true`) and `pve_vm_autostart` (default `true`) have role defaults and spec entries. Before, both were read as `| default(true)`. - New assert: `pve_vm_disk_size` must be set while `pve_vm_manage_disk` is true, unless the state is `absent`. It runs in validation, before any change. - New assert in `tasks/create.yml`, before the clone: `pve_vm_clone_vmid` must be set. It lives there because whether a clone happens is known only after the API lookup. - Only `pve_vm_exists` is a public fact. Every other fact, every registered result and the API auth header are now `__pve_vm_*`. That covers the former `pve_vm_needs_update`, `pve_vm_config`, `pve_vm_created`, `pve_vm_disk_resized` and the drift facts. - `pve_vm_api_host` still defaults to the `ansible_host` of `pve_vm_node` from hostvars. The README says to set it explicitly when the node is not an inventory host. - Otherwise behaviour is unchanged: drift detection, the `--check` previews and the stored-`cipassword` delete work as before. **Content scrub.** I ran this grep over the role, excluding molecule: ``` grep -rnEi 'rke2|clotho|lachesis|atropos|moirai|devops|homelab|home lab|rkdr|defame|kamino-runner|gitea-runner|hosts/|host_vars|group_vars|#[0-9]+|([0-9]{1,3}\.){3}[0-9]{1,3}' roles/pve_vm --exclude-dir=molecule ``` Result: ``` roles/pve_vm/meta/main.yml:5: author: Defame1297 roles/pve_vm/README.md:94: ipconfig0: "ip={{ ansible_host }}/24,gw=192.0.2.1" ``` Both hits are expected. The first is the Collection author, as in every role's `meta/main.yml`. The second is a documentation address (TEST-NET-1). I also searched the whole added diff, scenario included, for names of the source environment, inventory paths and private addresses. The only hits were the repository's own molecule run label and molecule's `group_vars:` key, the same as in `pve_lxc`. ## Verified The scenario playbooks ran locally as plays against a local connection, not in a container: - Converge passed, both normally and under `--check`. - Verify passed: - 7 refusal cases, each matching its expected message; - 2 positive validation cases; - 12 drift cases; - the three static assertions, which found all 8 `proxmox_kvm` tasks, including one inside a block. Mutation tests ran on scratch copies of the task files. Each mutation made the matching static assertion fail, and an unmutated copy passed: - `cipassword` in the `module_defaults` of the `proxmox_kvm` entry, and in a `group/community.proxmox.proxmox` entry; - a task file in a subdirectory, with a task two blocks deep under the short name `proxmox_kvm` and `cipassword` under `args:`; - an `action:` mapping with `module: community.proxmox.proxmox_kvm`; - a `local_action:` string `proxmox_kvm vmid=1 cipassword=x`; - the key `ansible.legacy.proxmox_kvm`; - a second, non-`no_log` task deleting `cipassword` through an `action:` mapping; - a harmless `action:` task, which passed as it should. Other checks: - `ansible-doc -t role mortis.kamino.pve_vm` renders the spec. - `python3 -m unittest discover -s tests/scripts`: 304 tests OK. - The commit-stage pre-commit hooks passed, including ansible-lint, yamllint, REUSE, gitleaks and the changelog fragment lint. - `scripts/select_molecule_scenarios.py` selects `roles/pve_vm/molecule/default`. - The pre-push `ansible-test sanity` passed. CI on `f3cab37` is all green: build run 6777, lint run 6778 and molecule run 6779. In run 6779 the `pve_vm/default` scenario finished with exit 0 after 40 s. Its duration entry in `scripts/run_molecule_scenarios.sh` stays at the estimate of 60 s, since the entry only orders the scenarios. ## Not verified - The API lifecycle is not exercised by molecule: lookup, clone, update, the stored-`cipassword` delete, resize, start, stop, restart and delete. There is no Proxmox API in the scenario. - The guest-side cloud-init wait (`cloud-init status --wait`) is untested on both releases, because the test images do not ship cloud-init. - The listed API privileges and the token privilege-separation note in the README come from the Proxmox documentation and the role's calls. They were not tested against a live node. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code:claude-opus-5-5 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Claude added the Kind/Feature label 2026-11-29 20:22:33 +00:00
Claude added 1 commit 2026-11-29 20:22:34 +00:00
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
f3cab37c7b
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
CODEOWNERS rules requested review from Defame1297 2026-11-29 20:22:34 +00:00
Defame1297 added 1 commit 2026-12-01 20:13:02 +00:00
Merge branch 'main' into feat/482-pve-vm-role
Build / build (pull_request) Successful in 56s
Lint / lint (pull_request) Successful in 4m48s
Molecule / molecule (pull_request) Successful in 37m37s
773de8eba4
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-12-01 20:13:12 +00:00
Defame1297 approved these changes 2026-12-01 20:13:24 +00:00
Defame1297 merged commit ceaa43c7ab into main 2026-12-01 20:56:45 +00:00
Defame1297 deleted branch feat/482-pve-vm-role 2026-12-01 20:56:47 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#489