Use this when automating VM creation or guest configuration with Ansible playbooks against VMware, libvirt or Proxmox.
Ansible
Ansible automates virtualization with agentless playbooks and modules such as community.vmware, community.libvirt and community.general.proxmox to create VMs, change hardware and configure the guest OS in one idempotent run.
1. Ansible manages VMs via modules (proxmox_kvm, vmware_guest, virt).
2. Use dynamic inventory.
3. Idempotent playbooks.
4. Vault for secrets.
5. Run in check mode first.
playbook → module → API → VM
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Checks Verify boundary
ansible-galaxy collection list | grep -E 'vmware|proxmox'
ansible-playbook vm.yml --check --diff
Step 2 Common mistakes Narrow the fault
- Collections not pinned (
requirements.yml). - Credentials in playbooks instead of Ansible Vault or a secret store.
- Not waiting for guest tools/IP before the next task (
wait_for).
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Module ok ≠ guest configured; that is a second play.
- Collections and SDKs must match the platform version.
- Check mode shows intent, not guest effects.
ansible-galaxy collection list | grep -E 'community.general|community.vmware|community.libvirt'— collections installedansible-playbook vm.yml --check— dry runansible-inventory --graph— dynamic inventory
ReferenceWhy it matters1 section · depth on demand
In depth
Ansible manages virtualization through collections: community.vmware/vmware.vmware, community.general.proxmox_kvm, microsoft.hyperv-style modules or ansible.windows with PowerShell, and community.libvirt.
- name: Clone VM from template
community.general.proxmox_kvm:
api_host: pve1
api_user: automation@pve
api_token_id: ci
api_token_secret: "{{ vault_pve_token }}"
clone: ubuntu-2404-tpl
newid: 130
name: web01
node: pve1
full: true
storage: local-zfs
Keep API credentials in Ansible Vault or an external secret store, never in playbooks.
ReferenceImportant terms & boundaries2 sections · depth on demand
Example
- name: Create VM from template
community.vmware.vmware_guest:
hostname: vcenter.corp.local
name: web01
template: tpl-debian12
datacenter: DC1
cluster: CL1
state: poweredon
Documented example, not captured output. Proxmox: community.general.proxmox_kvm.
Proxmox example
- community.general.proxmox_kvm:
api_host: pve1
api_user: automation@pve
api_token_id: ansible
api_token_secret: "{{ vault_pve_token }}"
clone: tpl-debian12
newid: 160
name: app06
node: pve1
Documented example, not captured output.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Automation → Ansible. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://libvirt.org/html/index.html · confidence 94%