You've already forked role_proxmox
refacto: Partial rewrite to manage nodes
This commit is contained in:
44
tasks/instance_vm_ha.yml
Normal file
44
tasks/instance_vm_ha.yml
Normal file
@@ -0,0 +1,44 @@
|
||||
---
|
||||
# tasks file for proxmox
|
||||
|
||||
- name: Build HA resources (vm:<vmid>) for node
|
||||
set_fact:
|
||||
ha_resources_for_node: >-
|
||||
{{ ['vm:'] | product(
|
||||
query('inventory_hostnames', 'type_proxmox_kvm:&zone_gaia') |
|
||||
sort |
|
||||
map('extract', hostvars) |
|
||||
selectattr('proxmox_instance_node', 'equalto', proxmox_instance_node) |
|
||||
map(attribute='proxmox_instance_vmid')
|
||||
) | map('join') | list }}
|
||||
|
||||
- name: Ensure HA services exist for VMs
|
||||
community.proxmox.proxmox_cluster_ha_resources:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
api_user: "{{ proxmox_api_user }}"
|
||||
comment: "Managed by Ansible"
|
||||
hastate: "{{ proxmox_instance_ha.state }}"
|
||||
max_relocate: "{{ proxmox_instance_ha.max_relocate }}"
|
||||
max_restart: "{{ proxmox_instance_ha.max_restart }}"
|
||||
name: "vm:{{ proxmox_instance_vmid }}"
|
||||
state: present
|
||||
become: true
|
||||
delegate_to: "{{ proxmox_delegate_to }}"
|
||||
|
||||
- name: Create HA node affinity rule
|
||||
community.proxmox.proxmox_cluster_ha_rules:
|
||||
api_host: "{{ proxmox_api_host }}"
|
||||
api_token_id: "{{ proxmox_api_token_id }}"
|
||||
api_token_secret: "{{ proxmox_api_token_secret }}"
|
||||
api_user: "{{ proxmox_api_user }}"
|
||||
comment: Managed by ansible
|
||||
disable: false
|
||||
name: "{{ proxmox_instance_node }}"
|
||||
nodes: ["{{ proxmox_instance_node }}"]
|
||||
resources: "{{ ha_resources_for_node }}"
|
||||
state: present
|
||||
type: node-affinity
|
||||
become: true
|
||||
delegate_to: "{{ proxmox_delegate_to }}"
|
||||
Reference in New Issue
Block a user