summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Berendt <berendt@b1-systems.de>2014-04-28 19:46:34 +0200
committerJames Cammarata <jimi@sngx.net>2014-05-07 08:25:50 -0500
commitce15813e70c63129b6d82fd7dc72a903dcb48381 (patch)
tree2cdb586e0f7260d164666f65398477e58ae76e2c
parentf05d4575607613b147b6ec15155b06775f1fee7c (diff)
downloadansible-ce15813e70c63129b6d82fd7dc72a903dcb48381.tar.gz
made enabled/disabled checks of apache2_module workable
-rw-r--r--library/web_infrastructure/apache2_module37
1 files changed, 14 insertions, 23 deletions
diff --git a/library/web_infrastructure/apache2_module b/library/web_infrastructure/apache2_module
index d85974323f..7b71a23cc9 100644
--- a/library/web_infrastructure/apache2_module
+++ b/library/web_infrastructure/apache2_module
@@ -1,7 +1,7 @@
#!/usr/bin/python
#coding: utf-8 -*-
-# (c) 2013, Christian Berendt <berendt@b1-systems.de>
+# (c) 2013-2014, Christian Berendt <berendt@b1-systems.de>
#
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -44,39 +44,31 @@ EXAMPLES = '''
- apache2_module: state=absent name=wsgi
'''
-def _module_is_enabled(module):
- name = module.params['name']
- a2enmod_binary = module.get_bin_path("a2enmod")
- result, stdout, stderr = module.run_command("%s -q %s" % (a2enmod_binary, name))
- return result == 0
-
-def _module_is_disabled(module):
- return _module_is_enabled(module) == False
+import re
def _disable_module(module):
name = module.params['name']
+ a2dismod_binary = module.get_bin_path("a2dismod")
+ result, stdout, stderr = module.run_command("%s %s" % (a2dismod_binary, name))
- if _module_is_disabled(module):
+ if re.match(r'.*already disabled.*', stdout):
module.exit_json(changed = False, result = "Success")
-
- result, stdout, stderr = module.run_command("a2dismod %s" % name)
- if result != 0:
+ elif result != 0:
module.fail_json(msg="Failed to disable module %s: %s" % (name, stdout))
-
- module.exit_json(changed = True, result = "Disabled")
+ else:
+ module.exit_json(changed = True, result = "Disabled")
def _enable_module(module):
name = module.params['name']
-
- if _module_is_enabled(module):
- module.exit_json(changed = False, result = "Success")
-
a2enmod_binary = module.get_bin_path("a2enmod")
result, stdout, stderr = module.run_command("%s %s" % (a2enmod_binary, name))
- if result != 0:
- module.fail_json(msg="Failed to enable module %s: %s" % (name, stdout))
- module.exit_json(changed = True, result = "Enabled")
+ if re.match(r'.*already enabled.*', stdout):
+ module.exit_json(changed = False, result = "Success")
+ elif result != 0:
+ module.fail_json(msg="Failed to enable module %s: %s" % (name, stdout))
+ else:
+ module.exit_json(changed = True, result = "Enabled")
def main():
module = AnsibleModule(
@@ -95,4 +87,3 @@ def main():
# import module snippets
from ansible.module_utils.basic import *
main()
-