Files
role_proxmox/tasks/ha.yml
2025-09-20 11:39:46 +02:00

42 lines
1.3 KiB
YAML

---
# tasks file for proxmox
- name: Add Proxmox VE host as HA group
ansible.builtin.blockinfile:
path: /etc/pve/ha/groups.cfg
append_newline: true
prepend_newline: true
block: |
group: {{ proxmox_instance_node }}
nodes {{ proxmox_instance_node }}
nofailback 0
restricted 0
marker: "# {mark} {{ proxmox_instance_node }}"
become: true
delegate_to: "{{ proxmox_delegate_to }}"
- name: Add VM to HA group
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 }}"
group: "{{ proxmox_instance_ha.group }}"
hastate: "{{ proxmox_instance_ha.state | default('started') }}"
max_relocate: "{{ proxmox_instance_ha.max_relocate | default(2) }}"
max_restart: "{{ proxmox_instance_ha.max_restart | default(3) }}"
name: "{{ inventory_hostname }}"
state: present
delegate_to: "{{ proxmox_delegate_to | default(omit) }}"
- name: Add ansible managed header
ansible.builtin.lineinfile:
path: "{{ item }}"
line: "# Ansible managed"
insertafter: BOF
become: true
loop:
- /etc/pve/ha/groups.cfg
- /etc/pve/ha/resources.cfg
delegate_to: "{{ proxmox_delegate_to }}"