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
This commit is contained in:
1 parent
7f28fccfe4
commit
f3cab37c7b
25 files changed
+1433
-7
No files matched your search
@@ -0,0 +1,197 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: Manage a Proxmox VE QEMU VM cloned from a template
|
||||
description:
|
||||
- >-
|
||||
Looks the VM up through the Proxmox API, deletes it when C(pve_vm_state) is absent and C(pve_vm_allow_destroy) is
|
||||
true, otherwise clones it from the template C(pve_vm_clone_vmid) when it does not exist, compares the live
|
||||
configuration with the desired one, updates it only on drift, grows the boot disk, applies the power state
|
||||
and waits for SSH and cloud-init when the VM is started.
|
||||
- >-
|
||||
Every API call is delegated to C(pve_vm_delegate) (the REST lookup of the config to localhost) and authenticates
|
||||
with C(pve_vm_api_user) (bare user name, C(@<pve_vm_api_realm>) is appended), C(pve_vm_api_token_id),
|
||||
C(pve_vm_api_token_secret) and C(pve_vm_api_host), applied through C(module_defaults), and with the header
|
||||
C(PVEAPIToken=<user>@<realm>!<token_id>=<secret>) for the REST lookup, which the role derives from them in
|
||||
C(vars/main.yml) (internal, not an input). The user and the token secret have no usable default: they are
|
||||
asserted non-empty in the input validation, before any change. C(community.proxmox) and, on the controller,
|
||||
the Python libraries C(proxmoxer) 2.3 or later and C(requests) must be installed. TLS certificates are not
|
||||
verified.
|
||||
- >-
|
||||
Also reads C(ansible_host) (SSH wait), C(inventory_hostname) (the VM name, lowercased with underscores replaced by
|
||||
dashes) and C(ansible_check_mode). The role sets the fact C(pve_vm_exists) for later roles and plays.
|
||||
- >-
|
||||
Cloud-init sets C(ciuser) from C(pve_vm_ci_user); an empty user is left out of the update and not compared for
|
||||
drift. The role never sets a cloud-init password (C(cipassword)) and deletes one stored on the VM on a real run.
|
||||
options:
|
||||
pve_vm_node:
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
- >-
|
||||
Name of the Proxmox node that owns the VM. When it is also an inventory host, its C(ansible_host) is the
|
||||
default of C(pve_vm_api_host).
|
||||
pve_vm_vmid:
|
||||
type: int
|
||||
required: true
|
||||
description:
|
||||
- VM id on the Proxmox node. For a clone it is the new id.
|
||||
pve_vm_state:
|
||||
type: str
|
||||
default: present
|
||||
choices: [present, started, stopped, absent]
|
||||
description:
|
||||
- >-
|
||||
C(present) keeps the VM configured without touching its power state. C(started) and C(stopped) also apply the
|
||||
power state, and C(started) additionally waits for SSH and cloud-init when C(pve_vm_wait_for_guest) is true.
|
||||
C(absent) deletes the VM, but only when C(pve_vm_allow_destroy) is true. Without it the role only looks the
|
||||
VM up and changes nothing, because creation, disk detection, update and power state are gated on a state
|
||||
other than C(absent).
|
||||
pve_vm_allow_destroy:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- Safety switch required before C(pve_vm_state=absent) deletes the VM.
|
||||
pve_vm_clone_vmid:
|
||||
type: raw
|
||||
description:
|
||||
- >-
|
||||
Template VM id to clone. Only read when the VM does not exist and the play is not in check mode. The type is
|
||||
not fixed, so it can be given as a Jinja expression that resolves to the id.
|
||||
pve_vm_full_clone:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- Full clone instead of a linked clone.
|
||||
pve_vm_delegate:
|
||||
type: str
|
||||
default: localhost
|
||||
description:
|
||||
- Host that executes the Proxmox API module tasks. The REST lookup of the VM config always runs on localhost.
|
||||
pve_vm_wait_for_guest:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
When true and C(pve_vm_state) is started, wait for SSH on port 22 of C(ansible_host) and then for
|
||||
C(cloud-init status --wait) on the guest.
|
||||
pve_vm_agent:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- Enable the QEMU guest agent. Compared with the live config for drift.
|
||||
pve_vm_onboot:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- Start the VM when the node boots. Compared with the live config for drift.
|
||||
pve_vm_autostart:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
Passed to the module as C(autostart) on update. Not compared for drift, because Proxmox does not return it in
|
||||
the VM config.
|
||||
pve_vm_memory:
|
||||
type: raw
|
||||
description:
|
||||
- Memory in MB. Omitted from the update when undefined. Compared as an integer for drift.
|
||||
pve_vm_cores:
|
||||
type: raw
|
||||
description:
|
||||
- CPU cores. Omitted from the update when undefined. Compared as an integer for drift.
|
||||
pve_vm_sockets:
|
||||
type: raw
|
||||
description:
|
||||
- CPU sockets. Omitted from the update when undefined. Compared as an integer for drift.
|
||||
pve_vm_network:
|
||||
type: raw
|
||||
description:
|
||||
- >-
|
||||
Mapping passed to the module as C(net), for example C(net0) with C(model), C(bridge), C(tag) and C(firewall).
|
||||
Omitted when undefined. Only C(net0) is compared for drift.
|
||||
pve_vm_ipconfig:
|
||||
type: raw
|
||||
description:
|
||||
- >-
|
||||
Mapping passed to the module as C(ipconfig), for example C(ipconfig0) with a string such as
|
||||
C(ip=<address>/24,gw=<gateway>). Omitted when undefined. Only C(ipconfig0) is compared for drift, token order
|
||||
ignored.
|
||||
pve_vm_nameservers:
|
||||
type: raw
|
||||
description:
|
||||
- Nameservers as a list, or a space or comma separated string. Omitted when undefined.
|
||||
pve_vm_sshkeys:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
Public keys written to the cloud-init C(sshkeys) field, one per line. Omitted when undefined. Proxmox stores
|
||||
them URL-encoded, so a change is not detected as drift and is only applied on a fresh clone, on other drift
|
||||
or with C(pve_vm_force_update).
|
||||
pve_vm_ci_user:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Cloud-init user (C(ciuser)). Left out of the update and not compared for drift when empty. Compared with the
|
||||
live C(ciuser) otherwise.
|
||||
pve_vm_force_update:
|
||||
type: bool
|
||||
default: false
|
||||
description:
|
||||
- Push cloud-init settings (user, sshkeys) and the whole configuration even without detected drift.
|
||||
pve_vm_manage_disk:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
Grow the boot disk to C(pve_vm_disk_size). While true, C(pve_vm_disk_size) must be set; the input validation
|
||||
asserts it unless C(pve_vm_state) is absent.
|
||||
pve_vm_disk_size:
|
||||
type: raw
|
||||
description:
|
||||
- >-
|
||||
Desired boot disk size, for example C(32G). Only the digits are compared with the current size in GB, and the
|
||||
disk is only ever grown.
|
||||
pve_vm_boot_disk:
|
||||
type: str
|
||||
default: scsi0
|
||||
description:
|
||||
- Disk key whose size is read and resized.
|
||||
pve_vm_reboot_if_required:
|
||||
type: bool
|
||||
default: true
|
||||
description:
|
||||
- Restart the VM after its boot disk was grown.
|
||||
pve_vm_api_user:
|
||||
type: str
|
||||
default: ""
|
||||
description:
|
||||
- >-
|
||||
Proxmox API user, the bare name without realm (C(@<pve_vm_api_realm>) is appended). Required: the role
|
||||
asserts it is non-empty before any change.
|
||||
pve_vm_api_realm:
|
||||
type: str
|
||||
default: pam
|
||||
description:
|
||||
- Authentication realm of C(pve_vm_api_user), appended as C(@<realm>) in C(module_defaults) and in the REST header.
|
||||
pve_vm_api_token_id:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
API token id, without the user part. Role default C(<pve_vm_api_user>-token), a Jinja expression in
|
||||
C(defaults/main.yml), so it is not repeated here.
|
||||
pve_vm_api_token_secret:
|
||||
type: str
|
||||
no_log: true
|
||||
description:
|
||||
- >-
|
||||
API token secret, normally vaulted. No default. Required: the role asserts it is set and non-empty before
|
||||
any change. Every task that carries it is C(no_log).
|
||||
pve_vm_api_host:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
Address of the Proxmox API (port 8006). Role default the C(ansible_host) of C(pve_vm_node) from hostvars, or
|
||||
empty when C(pve_vm_node) is undefined; a Jinja expression in C(defaults/main.yml), so it is not repeated
|
||||
here. Set it explicitly when the node is not an inventory host.
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: pve_vm
|
||||
namespace: mortis
|
||||
author: Defame1297
|
||||
license: GPL-3.0-or-later
|
||||
description: Clone, configure, resize, start, stop and delete Proxmox VE QEMU VMs through the Proxmox API, with cloud-init settings and drift detection.
|
||||
min_ansible_version: "2.22"
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- noble
|
||||
- resolute
|
||||
galaxy_tags:
|
||||
- proxmox
|
||||
- vm
|
||||
- cloudinit
|
||||
- provisioning
|
||||
dependencies: []
|
||||
Reference in new issue
Block a user