Files
Kamino/roles/pve_vm/tasks/create.yml
T
Defame1297 f3cab37c7b
Build / build (pull_request) Successful in 46s
Lint / lint (pull_request) Successful in 2m57s
Molecule / molecule (pull_request) Successful in 30m40s
feat(pve_vm): add the pve_vm role
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
2026-11-29 20:10:33 +00:00

30 lines
1.0 KiB
YAML

---
# Here, not in validate.yml: whether a clone happens is known only after the API lookup.
- name: Assert the template to clone is set
ansible.builtin.assert:
that:
- pve_vm_clone_vmid is defined
fail_msg: >-
VM {{ pve_vm_vmid }} does not exist on {{ pve_vm_node }}, so it is cloned, which needs
pve_vm_clone_vmid, the VM id of the template. Set it, or create the VM by other means.
quiet: true
- name: Clone VM from template
no_log: true # carries the API token secret
delegate_to: "{{ pve_vm_delegate }}"
community.proxmox.proxmox_kvm:
node: "{{ pve_vm_node }}"
clone: template
vmid: "{{ pve_vm_clone_vmid }}"
newid: "{{ pve_vm_vmid }}"
name: "{{ inventory_hostname | lower | replace('_', '-') }}"
full: "{{ pve_vm_full_clone }}"
timeout: 600
state: present
register: __pve_vm_clone
- name: Record that the VM was just cloned
ansible.builtin.set_fact:
# Forces one cloud-init update (ciuser, sshkeys) in update.yml.
__pve_vm_created: "{{ __pve_vm_clone is changed }}"