Repository: ansible-collections/community.general

Issue:
apache2_module: Relies on a2enmod / misleading error on CentOS
### Summary

The ansible `apache2_module` module relies on Debian-style (also sometimes called "Debianisms") binaries as `a2enmod` for managing `httpd`/`apache` modules. On CentOS this is not the case as this distribution doesn't use these binaries. 

On CentOS this module emits a misleading error:
````
None not found. Perhaps this system does not use None to manage apache
````

Responsible code:
https://github.com/ansible-collections/community.general/blob/da11a98cb734e99cc57f4ae6ec09d9199875c39b/plugins/modules/web_infrastructure/apache2_module.py#L207

### Issue Type

Bug Report

### Component Name

apache2_module

### Ansible Version

```console (paste below)
$ ansible --version

ansible 2.9.10
  config file = None
  configured module search path = ['/home/build/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 9.4.0]
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
(Empty)
```


### OS / Environment

WSL 2/Ubuntu 20.04 LTS (ansible client); CentOS 7.x (ansible target).

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
    - name: Enable mod_substitute
      apache2_module:
        name:  mod_substitute
        state: present
```


### Expected Results

`apache_module` ansible module manages the modules without errors.

### Actual Results

```console (paste below)
None not found. Perhaps this system does not use None to manage apache
```


### Code of Conduct

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


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

If these files are inaccurate, 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/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @berendt @n0trax @robinro
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
> The ansible `apache2_module` module relies on Debian-style (also sometimes called "Debianisms") binaries as `a2enmod` for managing `httpd`/`apache` modules. On CentOS this is not the case as this distribution doesn't use these binaries.

That's already documented, see https://docs.ansible.com/ansible/latest/collections/community/general/apache2_module_module.html#notes

(In case you wonder why this wasn't there yesterday: the docs were accidentally not updated after the last release, and the note only has been in there since then.)

> On CentOS this module emits a misleading error:
> 
> ```
> None not found. Perhaps this system does not use None to manage apache
> ```

This is definitely a bug that should be fixed. I'm working on a fix right now.

Resolving patch:
diff --git a/plugins/modules/web_infrastructure/apache2_module.py b/plugins/modules/web_infrastructure/apache2_module.py
--- a/plugins/modules/web_infrastructure/apache2_module.py
+++ b/plugins/modules/web_infrastructure/apache2_module.py
@@ -202,15 +202,17 @@ def _set_state(module, state):
                              result=success_msg,
                              warnings=module.warnings)
 
-        a2mod_binary = [module.get_bin_path(a2mod_binary)]
-        if a2mod_binary is None:
+        a2mod_binary_path = module.get_bin_path(a2mod_binary)
+        if a2mod_binary_path is None:
             module.fail_json(msg="%s not found. Perhaps this system does not use %s to manage apache" % (a2mod_binary, a2mod_binary))
 
+        a2mod_binary_cmd = [a2mod_binary_path]
+
         if not want_enabled and force:
             # force exists only for a2dismod on debian
-            a2mod_binary.append('-f')
+            a2mod_binary_cmd.append('-f')
 
-        result, stdout, stderr = module.run_command(a2mod_binary + [name])
+        result, stdout, stderr = module.run_command(a2mod_binary_cmd + [name])
 
         if _module_is_enabled(module) == want_enabled:
             module.exit_json(changed=True,


Test patch: