Skip to content

Commit

Permalink
pacemaker_cluster: implement check mode (#8081)
Browse files Browse the repository at this point in the history
* Implement check mode for pacemaker_cluster.

* Fix restart code.

Co-authored-by: Mario Lenz <[email protected]>

---------

Co-authored-by: Mario Lenz <[email protected]>
  • Loading branch information
felixfontein and mariolenz authored Mar 14, 2024
1 parent 6fab467 commit 17e275b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/pacemaker-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "pacemaker_cluster - actually implement check mode, which the module claims to support. This means that until now the module
also did changes in check mode (https://github.com/ansible-collections/community.general/pull/8081)."
8 changes: 8 additions & 0 deletions plugins/modules/pacemaker_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def main():
if cluster_state == state:
module.exit_json(changed=changed, out=cluster_state)
else:
if module.check_mode:
module.exit_json(changed=True)
set_cluster(module, state, timeout, force)
cluster_state = get_cluster_status(module)
if cluster_state == state:
Expand All @@ -201,12 +203,16 @@ def main():
if node_state[1].strip().lower() == state:
module.exit_json(changed=changed, out=cluster_state)
else:
if module.check_mode:
module.exit_json(changed=True)
# Set cluster status if needed
set_cluster(module, state, timeout, force)
cluster_state = get_node_status(module, node)
module.exit_json(changed=True, out=cluster_state)

if state in ['restart']:
if module.check_mode:
module.exit_json(changed=True)
set_cluster(module, 'offline', timeout, force)
cluster_state = get_cluster_status(module)
if cluster_state == 'offline':
Expand All @@ -220,6 +226,8 @@ def main():
module.fail_json(msg="Failed during the restart of the cluster, the cluster can't be stopped")

if state in ['cleanup']:
if module.check_mode:
module.exit_json(changed=True)
clean_cluster(module, timeout)
cluster_state = get_cluster_status(module)
module.exit_json(changed=True,
Expand Down

0 comments on commit 17e275b

Please sign in to comment.