-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathapache_module.py
103 lines (84 loc) · 2.89 KB
/
apache_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
'''
Manage Apache Modules
.. versionadded:: 2014.7.0
Enable and disable apache modules.
.. code-block:: yaml
Enable cgi module:
apache_module.enabled:
- name: cgi
Disable cgi module:
apache_module.disabled:
- name: cgi
'''
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
# Import salt libs
from salt.ext import six
def __virtual__():
'''
Only load if a2enmod is available.
'''
return 'apache_module' if 'apache.a2enmod' in __salt__ else False
def enabled(name):
'''
Ensure an Apache module is enabled.
.. versionadded:: 2016.3.0
name
Name of the Apache module
'''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
is_enabled = __salt__['apache.check_mod_enabled'](name)
if not is_enabled:
if __opts__['test']:
msg = 'Apache module {0} is set to be enabled.'.format(name)
ret['comment'] = msg
ret['changes']['old'] = None
ret['changes']['new'] = name
ret['result'] = None
return ret
status = __salt__['apache.a2enmod'](name)['Status']
if isinstance(status, six.string_types) and 'enabled' in status:
ret['result'] = True
ret['changes']['old'] = None
ret['changes']['new'] = name
else:
ret['result'] = False
ret['comment'] = 'Failed to enable {0} Apache module'.format(name)
if isinstance(status, six.string_types):
ret['comment'] = ret['comment'] + ' ({0})'.format(status)
return ret
else:
ret['comment'] = '{0} already enabled.'.format(name)
return ret
def disabled(name):
'''
Ensure an Apache module is disabled.
.. versionadded:: 2016.3.0
name
Name of the Apache module
'''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
is_enabled = __salt__['apache.check_mod_enabled'](name)
if is_enabled:
if __opts__['test']:
msg = 'Apache module {0} is set to be disabled.'.format(name)
ret['comment'] = msg
ret['changes']['old'] = name
ret['changes']['new'] = None
ret['result'] = None
return ret
status = __salt__['apache.a2dismod'](name)['Status']
if isinstance(status, six.string_types) and 'disabled' in status:
ret['result'] = True
ret['changes']['old'] = name
ret['changes']['new'] = None
else:
ret['result'] = False
ret['comment'] = 'Failed to disable {0} Apache module'.format(name)
if isinstance(status, six.string_types):
ret['comment'] = ret['comment'] + ' ({0})'.format(status)
return ret
else:
ret['comment'] = '{0} already disabled.'.format(name)
return ret