From d15a41d6c23c2bbedcfeef774577a48e933d83b3 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 22:32:52 +0100 Subject: [PATCH] [PR #8081/17e275bc backport][stable-6] pacemaker_cluster: implement check mode (#8093) pacemaker_cluster: implement check mode (#8081) * Implement check mode for pacemaker_cluster. * Fix restart code. Co-authored-by: Mario Lenz --------- Co-authored-by: Mario Lenz (cherry picked from commit 17e275bc0b830e40777df0a8b13146bd110fd8db) Co-authored-by: Felix Fontein --- changelogs/fragments/pacemaker-cluster.yml | 3 +++ plugins/modules/pacemaker_cluster.py | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 changelogs/fragments/pacemaker-cluster.yml diff --git a/changelogs/fragments/pacemaker-cluster.yml b/changelogs/fragments/pacemaker-cluster.yml new file mode 100644 index 0000000000..07e1ff3e04 --- /dev/null +++ b/changelogs/fragments/pacemaker-cluster.yml @@ -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)." diff --git a/plugins/modules/pacemaker_cluster.py b/plugins/modules/pacemaker_cluster.py index 47b827908f..60d8656ac3 100644 --- a/plugins/modules/pacemaker_cluster.py +++ b/plugins/modules/pacemaker_cluster.py @@ -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: @@ -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': @@ -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,