attempt to use proxmox api instead
This commit is contained in:
@@ -52,7 +52,6 @@ proxmox-template-clone/
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- community.general >= 8.0.0
|
- community.general >= 8.0.0
|
||||||
- community.proxmox >= 0.1.0
|
|
||||||
- ansible.posix >= 1.5.0
|
- ansible.posix >= 1.5.0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,5 @@
|
|||||||
collections:
|
collections:
|
||||||
- name: community.general
|
- name: community.general
|
||||||
version: ">=8.0.0"
|
version: ">=8.0.0"
|
||||||
- name: community.proxmox
|
|
||||||
version: ">=0.1.0"
|
|
||||||
- name: ansible.posix
|
- name: ansible.posix
|
||||||
version: ">=1.5.0"
|
version: ">=1.5.0"
|
||||||
|
|||||||
@@ -12,20 +12,32 @@
|
|||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
next_vmid: "{{ nextid_response.json.data }}"
|
next_vmid: "{{ nextid_response.json.data }}"
|
||||||
|
|
||||||
- name: Clone LXC from template
|
- name: Clone LXC from template via API
|
||||||
community.proxmox.proxmox:
|
ansible.builtin.uri:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ lxc_template_node }}/lxc/{{ lxc_template_id }}/clone"
|
||||||
api_user: "{{ proxmox_api_user }}"
|
method: POST
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
headers:
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
node: "{{ lxc_template_node }}"
|
body_format: form-urlencoded
|
||||||
clone: "{{ lxc_template_id }}"
|
body:
|
||||||
hostname: "{{ vm_hostname }}"
|
newid: "{{ next_vmid }}"
|
||||||
vmid: "{{ next_vmid }}"
|
hostname: "{{ vm_hostname }}"
|
||||||
full: true
|
full: "1"
|
||||||
storage: "local-lvm"
|
storage: "local-lvm"
|
||||||
timeout: 300
|
validate_certs: false
|
||||||
register: cloned_lxc
|
register: clone_result
|
||||||
|
|
||||||
|
- name: Wait for clone task to complete
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ lxc_template_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: 60
|
||||||
|
delay: 5
|
||||||
|
|
||||||
- name: Migrate LXC to target node
|
- name: Migrate LXC to target node
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
@@ -55,28 +67,25 @@
|
|||||||
when: lxc_template_node != target_node
|
when: lxc_template_node != target_node
|
||||||
|
|
||||||
- name: Configure LXC resources
|
- name: Configure LXC resources
|
||||||
community.proxmox.proxmox:
|
ansible.builtin.uri:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/lxc/{{ next_vmid }}/config"
|
||||||
api_user: "{{ proxmox_api_user }}"
|
method: PUT
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
headers:
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
node: "{{ target_node }}"
|
body_format: form-urlencoded
|
||||||
vmid: "{{ next_vmid }}"
|
body:
|
||||||
cores: "{{ cpu_cores }}"
|
cores: "{{ cpu_cores }}"
|
||||||
memory: "{{ ram_gb | int * 1024 }}"
|
memory: "{{ ram_gb | int * 1024 }}"
|
||||||
netif:
|
|
||||||
net0: "name=eth0,bridge=vmbr0,ip=dhcp"
|
net0: "name=eth0,bridge=vmbr0,ip=dhcp"
|
||||||
state: present
|
validate_certs: false
|
||||||
|
|
||||||
- name: Start the LXC container
|
- name: Start the LXC container
|
||||||
community.proxmox.proxmox:
|
ansible.builtin.uri:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/lxc/{{ next_vmid }}/status/start"
|
||||||
api_user: "{{ proxmox_api_user }}"
|
method: POST
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
headers:
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
node: "{{ target_node }}"
|
validate_certs: false
|
||||||
vmid: "{{ next_vmid }}"
|
|
||||||
state: started
|
|
||||||
|
|
||||||
- name: Set VMID fact for later use
|
- name: Set VMID fact for later use
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
|
|||||||
@@ -12,21 +12,32 @@
|
|||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
next_vmid: "{{ nextid_response.json.data }}"
|
next_vmid: "{{ nextid_response.json.data }}"
|
||||||
|
|
||||||
- name: Clone VM from template
|
- name: Clone VM from template via API
|
||||||
community.proxmox.proxmox_kvm:
|
ansible.builtin.uri:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ vm_template_node }}/qemu/{{ vm_template_id }}/clone"
|
||||||
api_user: "{{ proxmox_api_user }}"
|
method: POST
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
headers:
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
node: "{{ vm_template_node }}"
|
body_format: form-urlencoded
|
||||||
vmid: "{{ vm_template_id }}"
|
body:
|
||||||
clone: "template"
|
newid: "{{ next_vmid }}"
|
||||||
name: "{{ vm_hostname }}"
|
name: "{{ vm_hostname }}"
|
||||||
newid: "{{ next_vmid }}"
|
full: "1"
|
||||||
full: true
|
storage: "local-lvm"
|
||||||
storage: "local-lvm"
|
validate_certs: false
|
||||||
timeout: 300
|
register: clone_result
|
||||||
register: cloned_vm
|
|
||||||
|
- name: Wait for clone task to complete
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ vm_template_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: 60
|
||||||
|
delay: 5
|
||||||
|
|
||||||
- name: Migrate VM to target node
|
- name: Migrate VM to target node
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
@@ -57,28 +68,25 @@
|
|||||||
when: vm_template_node != target_node
|
when: vm_template_node != target_node
|
||||||
|
|
||||||
- name: Configure VM resources
|
- name: Configure VM resources
|
||||||
community.proxmox.proxmox_kvm:
|
ansible.builtin.uri:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/qemu/{{ next_vmid }}/config"
|
||||||
api_user: "{{ proxmox_api_user }}"
|
method: PUT
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
headers:
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
node: "{{ target_node }}"
|
body_format: form-urlencoded
|
||||||
vmid: "{{ next_vmid }}"
|
body:
|
||||||
cores: "{{ cpu_cores }}"
|
cores: "{{ cpu_cores }}"
|
||||||
memory: "{{ ram_gb | int * 1024 }}"
|
memory: "{{ ram_gb | int * 1024 }}"
|
||||||
net:
|
|
||||||
net0: "virtio,bridge=vmbr0"
|
net0: "virtio,bridge=vmbr0"
|
||||||
update: true
|
validate_certs: false
|
||||||
|
|
||||||
- name: Start the VM
|
- name: Start the VM
|
||||||
community.proxmox.proxmox_kvm:
|
ansible.builtin.uri:
|
||||||
api_host: "{{ proxmox_api_host }}"
|
url: "https://{{ proxmox_api_host }}:8006/api2/json/nodes/{{ target_node }}/qemu/{{ next_vmid }}/status/start"
|
||||||
api_user: "{{ proxmox_api_user }}"
|
method: POST
|
||||||
api_token_id: "{{ proxmox_api_token_id }}"
|
headers:
|
||||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
Authorization: "PVEAPIToken={{ proxmox_api_user }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
|
||||||
node: "{{ target_node }}"
|
validate_certs: false
|
||||||
vmid: "{{ next_vmid }}"
|
|
||||||
state: started
|
|
||||||
|
|
||||||
- name: Set VMID fact for later use
|
- name: Set VMID fact for later use
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
|
|||||||
Reference in New Issue
Block a user