--- - name: List VMs, Templates, and Clone Ubuntu server on Proxmox hosts: proxmox.localdomain gather_facts: false vars: api_host: 192.168.1.162 api_user: root@pam api_token_id: mytoki api_token_secret: ea5114f5-ed39-4277-ac09-a32984be5bc9 proxmox_node: pve # Add your Proxmox node name here vars_prompt: - name: new_vm_name prompt: Enter the name for the new VM private: false tasks: - name: List all VMs and templates community.general.proxmox_vm_info: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" validate_certs: false register: vms_info - name: Print VM and template names and states ansible.builtin.debug: msg: "{{ item.name }} - {{ item.status }}" loop: "{{ vms_info.proxmox_vms }}" - name: Find VMID based on VM name ansible.builtin.set_fact: source_vmid: "{{ item.vmid }}" loop: "{{ vms_info.proxmox_vms }}" when: item.name == "ubu-srv01" - name: Debug source VMID ansible.builtin.debug: msg: "Source VMID: {{ source_vmid }}" - name: Clone VM to create new Ubuntu server community.general.proxmox_kvm: api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" api_host: "{{ api_host }}" clone: ubu-srv01 name: "{{ new_vm_name }}" node: "{{ proxmox_node }}" storage: local format: qcow2 full: true timeout: 240 validate_certs: false - name: List all VMs and templates after cloning community.general.proxmox_vm_info: api_host: "{{ api_host }}" api_user: "{{ api_user }}" api_token_id: "{{ api_token_id }}" api_token_secret: "{{ api_token_secret }}" validate_certs: false register: vms_info_after_clone - name: Print VM and template names and states after cloning ansible.builtin.debug: msg: "{{ item.name }} - {{ item.status }}" loop: "{{ vms_info_after_clone.proxmox_vms }}"