Searches for template names instead of ids
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
---
|
---
|
||||||
lxc_template_id: "128"
|
lxc_template_name: "ubuntu24lxc"
|
||||||
lxc_template_hostname: "ubuntu24lxc"
|
lxc_template_hostname: "ubuntu24lxc"
|
||||||
|
|||||||
@@ -16,6 +16,23 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Target node {{ target_node }} will use storage: {{ target_storage }}"
|
msg: "Target node {{ target_node }} will use storage: {{ target_storage }}"
|
||||||
|
|
||||||
|
- name: Get list of LXC containers on target node
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/lxc"
|
||||||
|
method: GET
|
||||||
|
headers:
|
||||||
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
|
validate_certs: false
|
||||||
|
register: lxc_list
|
||||||
|
|
||||||
|
- name: Find template VMID by name
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
lxc_template_id: "{{ (lxc_list.json.data | selectattr('name', 'equalto', lxc_template_name) | first).vmid }}"
|
||||||
|
|
||||||
|
- name: Display found template
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Found template '{{ lxc_template_name }}' with VMID {{ lxc_template_id }} on {{ target_node }}"
|
||||||
|
|
||||||
- name: Clone LXC from template on target node
|
- name: Clone LXC from template on target node
|
||||||
community.proxmox.proxmox:
|
community.proxmox.proxmox:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
api_host: "{{ proxmox_api_host }}"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
---
|
---
|
||||||
vm_template_id: "118"
|
vm_template_name: "ubuntu24vm"
|
||||||
vm_template_hostname: "ubuntu24vm"
|
vm_template_hostname: "ubuntu24vm"
|
||||||
|
|||||||
@@ -16,6 +16,23 @@
|
|||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: "Target node {{ target_node }} will use storage: {{ target_storage }}"
|
msg: "Target node {{ target_node }} will use storage: {{ target_storage }}"
|
||||||
|
|
||||||
|
- name: Get list of VMs on target node
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/qemu"
|
||||||
|
method: GET
|
||||||
|
headers:
|
||||||
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
|
validate_certs: false
|
||||||
|
register: vm_list
|
||||||
|
|
||||||
|
- name: Find template VMID by name
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
vm_template_id: "{{ (vm_list.json.data | selectattr('name', 'equalto', vm_template_name) | first).vmid }}"
|
||||||
|
|
||||||
|
- name: Display found template
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Found template '{{ vm_template_name }}' with VMID {{ vm_template_id }} on {{ target_node }}"
|
||||||
|
|
||||||
- name: Clone VM from template on target node
|
- name: Clone VM from template on target node
|
||||||
community.proxmox.proxmox_kvm:
|
community.proxmox.proxmox_kvm:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
api_host: "{{ proxmox_api_host }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user