finding node where template lives
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
---
|
||||
lxc_template_id: "109"
|
||||
lxc_template_node: "homestrg1"
|
||||
|
||||
@@ -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 }}"
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
---
|
||||
vm_template_id: "133"
|
||||
vm_template_node: "homestrg1"
|
||||
|
||||
@@ -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: "{{ vm_template_node }}"
|
||||
vmid: "{{ vm_template_id }}"
|
||||
clone: "template"
|
||||
name: "{{ vm_hostname }}"
|
||||
@@ -28,6 +28,34 @@
|
||||
timeout: 300
|
||||
register: cloned_vm
|
||||
|
||||
- name: Migrate VM to target node
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ vm_template_node }}/qemu/{{ 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 }}"
|
||||
online: "0"
|
||||
with-local-disks: "1"
|
||||
validate_certs: false
|
||||
when: vm_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 }}/qemu/{{ next_vmid }}/status/current"
|
||||
method: GET
|
||||
headers:
|
||||
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||
validate_certs: false
|
||||
register: vm_status
|
||||
until: vm_status.status == 200
|
||||
retries: 30
|
||||
delay: 10
|
||||
when: vm_template_node != target_node
|
||||
|
||||
- name: Configure VM resources
|
||||
community.proxmox.proxmox_kvm:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
|
||||
Reference in New Issue
Block a user