Skip to content

Commit b81be42

Browse files
authored
Merge pull request #50 from cloudscale-ch/ha-groups
HA groups
2 parents 5998a74 + 9d711a3 commit b81be42

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,22 @@ pve_datacenter_cfg:
435435
keyboard: en-us
436436
```
437437

438+
You can also configure [HA manager groups][ha-group]:
439+
```
440+
pve_cluster_ha_groups: [] # List of HA groups to create in PVE.
441+
```
442+
443+
This example creates a group "lab_node01" for resources assigned to the
444+
lab-node01 host:
445+
```
446+
pve_cluster_ha_groups:
447+
- name: lab_node01
448+
comment: "My HA group"
449+
nodes: "lab-node01"
450+
nofailback: 0
451+
restricted: 0
452+
```
453+
438454
All configuration options supported in the datacenter.cfg file are documented in the
439455
[Proxmox manual datacenter.cfg section][datacenter-cfg].
440456

@@ -633,3 +649,4 @@ Michael Holasek ([@mholasek](https://github.com/mholasek))
633649
[storage-module]: https://github.com/lae/ansible-role-proxmox/blob/master/library/proxmox_storage.py
634650
[datacenter-cfg]: https://pve.proxmox.com/wiki/Manual:_datacenter.cfg
635651
[ceph_volume]: https://github.com/ceph/ceph-ansible/blob/master/library/ceph_volume.py
652+
[ha-group]: https://pve.proxmox.com/wiki/High_Availability#ha_manager_groups

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pve_cluster_clustername: "{{ pve_group }}"
3232
# pve_cluster_addr0: "{{ ansible_default_ipv4.address }}"
3333
# pve_cluster_addr1: "{{ ansible_eth1.ipv4.address }}
3434
pve_datacenter_cfg: {}
35+
pve_cluster_ha_groups: []
3536
pve_ssl_letsencrypt: false
3637
pve_groups: []
3738
pve_users: []

tasks/pve_cluster_config.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,37 @@
6767
when:
6868
- "_pve_active_cluster is not defined"
6969
- "inventory_hostname != groups[pve_group][0]"
70+
71+
- name: Check for PVE cluster HA groups
72+
proxmox_query:
73+
query: "/cluster/ha/groups"
74+
register: _ha_group_list
75+
when: "inventory_hostname == groups[pve_group][0]"
76+
77+
- name: Create PVE cluster HA groups
78+
command: >-
79+
ha-manager groupadd {{ item.name }}
80+
-comment "{{ item.comment | default('') }}"
81+
-nodes "{{ item.nodes }}"
82+
{% if 'nofailback' in item %}
83+
-nofailback {{ item.nofailback }}
84+
{% endif %}
85+
{% if 'restricted' in item %}
86+
-restricted {{ item.restricted }}
87+
{% endif %}
88+
when:
89+
- "inventory_hostname == groups[pve_group][0]"
90+
- item.name not in _ha_group_list.response | json_query("[*].group")
91+
with_items: "{{ pve_cluster_ha_groups }}"
92+
93+
- name: Update PVE cluster HA groups
94+
command: >-
95+
ha-manager groupset {{ item.0.name }} -{{ item.1 }} "{{ item.0[item.1] }}"
96+
when:
97+
- "inventory_hostname == groups[pve_group][0]"
98+
- item.0.name in _ha_group_list.response | json_query("[*].group")
99+
- item.1 in item.0
100+
- item.0[item.1] != _ha_group_list.response
101+
| json_query("[?group=='" + item.0.name + "']." + item.1) | first
102+
loop: "{{ pve_cluster_ha_groups
103+
| product(['comment', 'nodes', 'nofailback', 'restricted']) | list }}"

tests/group_vars/all

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ pve_ssl_certificate: "{{ lookup('file', ssl_host_cert_path) }}"
1515
pve_cluster_enabled: yes
1616
pve_datacenter_cfg:
1717
console: xtermjs
18+
pve_cluster_ha_groups:
19+
- name: proxmox_5_01
20+
comment: "Resources on proxmox-5-01"
21+
nodes: proxmox-5-01
22+
restricted: 1
1823
pve_groups:
1924
- name: Admins
2025
comment: Administrators of this PVE cluster

tests/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@
8080
assert:
8181
that: "'console: xtermjs' in datacenter_cfg.content | b64decode"
8282

83+
- name: Query PVE HA groups
84+
command: "pvesh get /cluster/ha/groups --output=json"
85+
register: _ha_group_list
86+
run_once: true
87+
88+
- name: Check PVE HA group configuration
89+
assert:
90+
that:
91+
- item.name == ha_group.group
92+
- item.comment == ha_group.comment
93+
- item.nodes == ha_group.nodes
94+
- item.restricted == ha_group.restricted
95+
- "'nofailback' not in ha_group"
96+
vars:
97+
ha_group: '{{ _ha_group_list.stdout | from_json
98+
| json_query("[?group==''" + item.name + "'']") | first }}'
99+
with_items: "{{ pve_cluster_ha_groups }}"
100+
83101
- block:
84102
- name: pvedaemon service status
85103
shell: "journalctl --no-pager -xu pvedaemon.service"

0 commit comments

Comments
 (0)