Skip to content

Commit 19ec406

Browse files
authored
fix idempotency in proxmox_cluster_ha_groups module (#139)
* fix idempotency of proxmox_cluster_ha_groups module * fix changed of proxmox_cluster_ha_groups module * add changelog fragment * fixup! fix changed of proxmox_cluster_ha_groups module
1 parent ace10fa commit 19ec406

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- proxmox_cluster_ha_groups - fix idempotency in proxmox_cluster_ha_groups module (https://github.com/ansible-collections/community.proxmox/issues/138, https://github.com/ansible-collections/community.proxmox/pull/139).

plugins/modules/proxmox_cluster_ha_groups.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
List of cluster node members, where a priority can be given to each node. A resource bound to a group will run on the available nodes with the
4545
highest priority. If there are more nodes in the highest priority class, the services will get distributed to those nodes. The priorities have a
4646
relative meaning only. The higher the number, the higher the priority.
47+
It can either be a string C(node_name:priority,node_name:priority) or an actual list of strings.
4748
required: false
48-
type: str
49+
type: list
50+
elements: str
4951
nofailback:
5052
description: |
5153
The CRM tries to run services on the node with the highest priority. If a node with higher priority comes online, the CRM migrates the service to
@@ -118,7 +120,7 @@ def _delete(self, name):
118120
def create(self, groups, name, comment, nodes, nofailback, restricted):
119121
data = {
120122
"comment": comment,
121-
"nodes": nodes,
123+
"nodes": ",".join(nodes),
122124
"nofailback": int(nofailback),
123125
"restricted": int(restricted)
124126
}
@@ -127,6 +129,10 @@ def create(self, groups, name, comment, nodes, nofailback, restricted):
127129
if group["group"] != name:
128130
continue
129131

132+
group["nodes"] = sorted(
133+
group.get("nodes", "").split(",")
134+
)
135+
130136
if (
131137
group.get("comment", ""),
132138
group.get("nodes", ""),
@@ -139,6 +145,7 @@ def create(self, groups, name, comment, nodes, nofailback, restricted):
139145
return True
140146

141147
self._post(group=name, **data)
148+
return True
142149

143150
def delete(self, groups, name):
144151
for group in groups:
@@ -157,7 +164,7 @@ def run_module():
157164
state=dict(choices=['present', 'absent'], required=True),
158165
name=dict(type='str', required=True),
159166
comment=dict(type='str', required=False),
160-
nodes=dict(type='str', required=False),
167+
nodes=dict(type='list', elements='str', required=False),
161168
nofailback=dict(type='bool', default=False),
162169
restricted=dict(type='bool', default=False),
163170
)
@@ -177,7 +184,7 @@ def run_module():
177184

178185
name = module.params['name']
179186
comment = module.params['comment']
180-
nodes = module.params['nodes']
187+
nodes = sorted(module.params['nodes'])
181188
nofailback = module.params['nofailback']
182189
restricted = module.params['restricted']
183190
try:

0 commit comments

Comments
 (0)