Skip to content

Commit

Permalink
apache2_module generates false/misleading warning (#5793)
Browse files Browse the repository at this point in the history
* Add parameter warn_mpm_module to control when warning are raised

* Remoe whitespace

* Add changelog fragment

* Add missing license

* Update changelogs/fragments/5793-apache2-module-npm-warnings.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/apache2_module.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/apache2_module.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update tests/integration/targets/apache2_module/tasks/635-apache2-misleading-warning.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Refining integration test - previous was invalid

* False to false

* refactor assertion for suse

* Revert "refactor assertion for suse"

This reverts commit 61b86e7.

* Excluding test on Suse

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 756c077)
  • Loading branch information
Warkdev authored and patchback[bot] committed Jan 14, 2023
1 parent 16c7615 commit c5c11d7
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/5793-apache2-module-npm-warnings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- apache2_module - add module argument ``warn_mpm_absent`` to control whether warning are raised in some edge cases (https://github.com/ansible-collections/community.general/pull/5793).
28 changes: 24 additions & 4 deletions plugins/modules/apache2_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
- Ignore configuration checks about inconsistent module configuration. Especially for mpm_* modules.
type: bool
default: false
warn_mpm_absent:
description:
- Control the behavior of the warning process for MPM modules.
type: bool
default: true
version_added: 6.3.0
requirements: ["a2enmod","a2dismod"]
notes:
- This does not work on RedHat-based distributions. It does work on Debian- and SuSE-based distributions.
Expand Down Expand Up @@ -78,6 +84,18 @@
name: mpm_worker
ignore_configcheck: true
- name: Disable mpm_event, enable mpm_prefork and ignore warnings about missing mpm module
community.general.apache2_module:
name: "{{ item.module }}"
state: "{{ item.state }}"
warn_mpm_absent: false
ignore_configcheck: true
loop:
- module: mpm_event
state: absent
- module: mpm_prefork
state: present
- name: Enable dump_io module, which is identified as dumpio_module inside apache2
community.general.apache2_module:
state: present
Expand Down Expand Up @@ -140,10 +158,11 @@ def _module_is_enabled(module):
error_msg = "Error executing %s: %s" % (control_binary, stderr)
if module.params['ignore_configcheck']:
if 'AH00534' in stderr and 'mpm_' in module.params['name']:
module.warnings.append(
"No MPM module loaded! apache2 reload AND other module actions"
" will fail if no MPM module is loaded immediately."
)
if module.params['warn_mpm_absent']:
module.warnings.append(
"No MPM module loaded! apache2 reload AND other module actions"
" will fail if no MPM module is loaded immediately."
)
else:
module.warnings.append(error_msg)
return False
Expand Down Expand Up @@ -249,6 +268,7 @@ def main():
force=dict(type='bool', default=False),
state=dict(default='present', choices=['absent', 'present']),
ignore_configcheck=dict(type='bool', default=False),
warn_mpm_absent=dict(type='bool', default=True),
),
supports_check_mode=True,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# This test represent the misleading behavior of the following issue: https://github.com/ansible-collections/community.general/issues/635
- name: Disable MPM event module
apache2_module:
name: "{{ item.module}}"
state: "{{ item.state}}"
ignore_configcheck: true
register: disable_mpm_modules
with_items:
- { module: mpm_event, state: absent }
- { module: mpm_prefork, state: present }

- assert:
that:
- "'warnings' in disable_mpm_modules"
- disable_mpm_modules["warnings"] == [
"No MPM module loaded! apache2 reload AND other module actions will fail if no MPM module is loaded immediately.",
"No MPM module loaded! apache2 reload AND other module actions will fail if no MPM module is loaded immediately."
]

- name: Enable MPM event module - Revert previous change
apache2_module:
name: "{{ item.module}}"
state: "{{ item.state}}"
ignore_configcheck: true
register: disable_mpm_modules
with_items:
- { module: mpm_prefork, state: absent }
- { module: mpm_event, state: present }

- name: Disable MPM event module
apache2_module:
name: "{{ item.module}}"
state: "{{ item.state}}"
ignore_configcheck: true
warn_mpm_absent: false
register: disable_mpm_modules
with_items:
- { module: mpm_event, state: absent }
- { module: mpm_prefork, state: present }

- assert:
that:
- "'warnings' not in disable_mpm_modules"
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
- mpm_worker
- mpm_event
- mpm_prefork
ignore_errors: yes
ignore_errors: true
register: remove_with_configcheck

- name: ensure configcheck fails task with when run without mpm modules
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/targets/apache2_module/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@
that: modules_before.stdout == modules_after.stdout
when: ansible_os_family in ['Debian', 'Suse']
# centos/RHEL does not have a2enmod/a2dismod

- name: include misleading warning test
include: 635-apache2-misleading-warning.yml
when: ansible_os_family in ['Debian']
# Suse has mpm_event module compiled within the base apache2

0 comments on commit c5c11d7

Please sign in to comment.