Files
ansible/clone_ubu1.yml
2024-06-14 08:40:04 +02:00

69 lines
2.1 KiB
YAML

---
- name: List VMs, Templates, and Clone Ubuntu server on Proxmox
hosts: proxmox.localdomain
gather_facts: no
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: no
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: no
register: vms_info
- name: Print VM and template names and states
debug:
msg: "{{ item.name }} - {{ item.status }}"
loop: "{{ vms_info.proxmox_vms }}"
- name: Find VMID based on VM name
set_fact:
source_vmid: "{{ item.vmid }}"
loop: "{{ vms_info.proxmox_vms }}"
when: item.name == "ubu-srv01"
- name: Debug source VMID
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: no
- 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: no
register: vms_info_after_clone
- name: Print VM and template names and states after cloning
debug:
msg: "{{ item.name }} - {{ item.status }}"
loop: "{{ vms_info_after_clone.proxmox_vms }}"