finding node where template lives

This commit is contained in:
2026-02-02 14:06:30 -05:00
parent 7755e65756
commit 9a4bc8e387
4 changed files with 59 additions and 2 deletions

View File

@@ -1,2 +1,3 @@
---
lxc_template_id: "109"
lxc_template_node: "homestrg1"

View File

@@ -18,7 +18,7 @@
api_user: "{{ proxmox_api_user }}"
api_token_id: "{{ proxmox_api_token_id }}"
api_token_secret: "{{ proxmox_api_token_secret }}"
node: "{{ target_node }}"
node: "{{ lxc_template_node }}"
clone: "{{ lxc_template_id }}"
hostname: "{{ vm_hostname }}"
vmid: "{{ next_vmid }}"
@@ -27,6 +27,33 @@
timeout: 300
register: cloned_lxc
- name: Migrate LXC to target node
ansible.builtin.uri:
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ lxc_template_node }}/lxc/{{ next_vmid }}/migrate"
method: POST
headers:
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
body_format: form-urlencoded
body:
target: "{{ target_node }}"
restart: "0"
validate_certs: false
when: lxc_template_node != target_node
register: migrate_result
- name: Wait for migration to complete
ansible.builtin.uri:
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/lxc/{{ next_vmid }}/status/current"
method: GET
headers:
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
validate_certs: false
register: lxc_status
until: lxc_status.status == 200
retries: 30
delay: 10
when: lxc_template_node != target_node
- name: Configure LXC resources
community.proxmox.proxmox:
api_host: "{{ proxmox_api_host }}"