feat: Create role

This commit is contained in:
2024-05-13 18:03:03 +02:00
parent ff3a9a8e69
commit d8fb5b7c2d
11 changed files with 681 additions and 4 deletions

44
tasks/instance_vm_ha.yml Normal file
View 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 }}"