Skip to content

Commit

Permalink
Fix bug ansible#5328 apache module loading
Browse files Browse the repository at this point in the history
Currently, the apache2_module module parses apache configs
for correctness when enabling or disabling apache2 modules.

This behavior introduced a conflict condition when transitioning
between certain modules, such as mpm_worker and mpm_event.

This change only parses apache's configs during check mode,
otherwise it parses the stdout results of attempted to enabled
or disable modules to determine change state.
  • Loading branch information
Michael Gugino committed Nov 1, 2016
1 parent d2106f1 commit 55b1813
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions web_infrastructure/apache2_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,25 @@ def _set_state(module, state):
a2mod_binary = {'present': 'a2enmod', 'absent': 'a2dismod'}[state]
success_msg = "Module %s %s" % (name, state_string)

if _module_is_enabled(module) != want_enabled:
if module.check_mode:
module.exit_json(changed = True, result = success_msg)
if module.check_mode:
module.exit_json(changed = _module_is_enabled(module) != want_enabled, result = success_msg)

a2mod_binary = module.get_bin_path(a2mod_binary)
if a2mod_binary 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 = module.get_bin_path(a2mod_binary)
if a2mod_binary is None:
module.fail_json(msg="%s not found. Perhaps this system does not use %s to manage apache" % (a2mod_binary, a2mod_binary))

if not want_enabled and force:
# force exists only for a2dismod on debian
a2mod_binary += ' -f'
if not want_enabled and force:
# force exists only for a2dismod on debian
a2mod_binary += ' -f'

result, stdout, stderr = module.run_command("%s %s" % (a2mod_binary, name))
result, stdout, stderr = module.run_command("%s %s" % (a2mod_binary, name))

if _module_is_enabled(module) == want_enabled:
module.exit_json(changed = True, result = success_msg)
else:
module.fail_json(msg="Failed to set module %s to %s: %s" % (name, state_string, stdout), rc=result, stdout=stdout, stderr=stderr)
else:
if result != 0:
module.fail_json(msg="Failed to set module %s to %s: %s" % (name, state_string, stdout), rc=result, stdout=stdout, stderr=stderr)
elif re.match(r'.*(already (disabled|enabled|present)|not present)', stdout, re.S):
module.exit_json(changed = False, result = success_msg)
else:
module.exit_json(changed = True, result = success_msg)

def main():
module = AnsibleModule(
Expand Down

0 comments on commit 55b1813

Please sign in to comment.