feat(proxmox): add k3s agents and refine VM provisioning
Signed-off-by: Tuan-Dat Tran <tuan-dat.tran@tudattr.dev>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
cores: "{{ vm.cores }}"
|
||||
memory: "{{ vm.memory }}"
|
||||
net: "{{ vm.net }}"
|
||||
hostpci: "{{ vm.hostpci | default({})}}"
|
||||
hostpci: "{{ vm.hostpci | default({}) }}"
|
||||
scsihw: "virtio-scsi-pci"
|
||||
ostype: "l26"
|
||||
tags: "{{ proxmox_tags }}"
|
||||
@@ -20,8 +20,7 @@
|
||||
boot: "order=scsi0"
|
||||
cpu: "x86-64-v2-AES"
|
||||
ciuser: "{{ vm.ciuser }}"
|
||||
# cipassword: "{{ vm_secrets[proxmox_secrets_prefix + '_' + vm.name.replace('-', '_')] }}"
|
||||
cipassword: "flyff369"
|
||||
cipassword: "{{ vm_secrets[proxmox_secrets_prefix + '_' + vm.name.replace('-', '_')] }}"
|
||||
ipconfig:
|
||||
ipconfig0: "ip=dhcp"
|
||||
sshkeys: "{{ vm.sshkeys }}"
|
||||
|
||||
@@ -33,29 +33,12 @@
|
||||
vmid: "{{ vm.vmid }}"
|
||||
state: started
|
||||
|
||||
- name: Stop VM
|
||||
community.general.proxmox_kvm:
|
||||
api_user: "{{ proxmox_api_user }}@pam"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
api_host: "192.168.20.12"
|
||||
node: "{{ vm.node }}"
|
||||
vmid: "{{ vm.vmid }}"
|
||||
state: stopped
|
||||
force: true
|
||||
- name: Retry stopping VM
|
||||
ansible.builtin.include_tasks: ./57_stop_and_verify_vm.yml
|
||||
|
||||
- name: Wait until VM is fully stopped
|
||||
community.general.proxmox_vm_info:
|
||||
api_user: "{{ proxmox_api_user }}@pam"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
api_host: "192.168.20.12"
|
||||
node: "{{ vm.node }}"
|
||||
vmid: "{{ vm.vmid }}"
|
||||
register: vm_status_check
|
||||
until: vm_status_check.proxmox_vms[0].status == "stopped"
|
||||
retries: 24
|
||||
delay: 5
|
||||
- name: Pause for 5 seconds for api
|
||||
ansible.builtin.pause:
|
||||
seconds: 5
|
||||
|
||||
- name: Start VM
|
||||
community.general.proxmox_kvm:
|
||||
|
||||
39
roles/proxmox/tasks/57_stop_and_verify_vm.yml
Normal file
39
roles/proxmox/tasks/57_stop_and_verify_vm.yml
Normal file
@@ -0,0 +1,39 @@
|
||||
- name: "Wait until success"
|
||||
block:
|
||||
- name: Set the retry count
|
||||
set_fact:
|
||||
retry_count: "{{ 0 if retry_count is undefined else retry_count | int + 1 }}"
|
||||
|
||||
- name: Stop VM
|
||||
community.general.proxmox_kvm:
|
||||
api_user: "{{ proxmox_api_user }}@pam"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
api_host: "192.168.20.12"
|
||||
node: "{{ vm.node }}"
|
||||
vmid: "{{ vm.vmid }}"
|
||||
state: stopped
|
||||
force: true
|
||||
|
||||
- name: Wait until VM is fully stopped
|
||||
community.general.proxmox_vm_info:
|
||||
api_user: "{{ proxmox_api_user }}@pam"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
api_host: "192.168.20.12"
|
||||
node: "{{ vm.node }}"
|
||||
vmid: "{{ vm.vmid }}"
|
||||
register: vm_status_check
|
||||
failed_when: vm_status_check.proxmox_vms[0].status != "stopped"
|
||||
rescue:
|
||||
- name: Check for retry count
|
||||
fail:
|
||||
msg: Ended after 24 retries
|
||||
when: retry_count|int == 24
|
||||
|
||||
- name: Wait 5s
|
||||
ansible.builtin.pause:
|
||||
seconds: 5
|
||||
|
||||
- name: "Failed to stop VM - Retrying..."
|
||||
include_tasks: ./57_stop_and_verify_vm.yml
|
||||
Reference in New Issue
Block a user