Repository: ansible-collections/community.general

Issue:
check_mode of community.general.pacemaker_cluster module
### Summary

I created a playbook to set the cluster state to online or offline using the community.general.pacemaker_cluster module. Even if you run ansible-playbook with the "--check" option, it will be ignored and the cluster state will change.

Is this a bug? Please let me know if there is a workaround.

### Issue Type

Bug Report

### Component Name

community.general.pacemaker_cluster module

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.15.9]
```

python3.9

### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
community.general 7.5.2

```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
CONFIG_FILE() = None
```


### OS / Environment

control node:RHEL8
target node:RHEL9

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
- name: Set cluster
  hosts: target1
  become: true
  gather_facts: false
  tasks:
    - name: Set cluster no.1
      community.general.pacemaker_cluster:
        state: offline
```


### Expected Results

When I run it with the --check option while online, I thought it would remain online, but it changed to offline.

### Actual Results

```console (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/pacemaker_cluster.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/pacemaker_cluster.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @matbu
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
That's clearly a bug, and a dangerous one. There's no workaround other than "do not use this module in check mode" :(

Resolving patch:
diff --git a/plugins/modules/pacemaker_cluster.py b/plugins/modules/pacemaker_cluster.py
--- 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,


Test patch: