feat: Create role

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

41
tasks/ha.yml Normal file
View File

@@ -0,0 +1,41 @@
---
# 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 }}"