mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Further service module tweaks
This commit is contained in:
parent
e9c4eb36d1
commit
ff82f0a168
2 changed files with 13 additions and 11 deletions
|
@ -134,9 +134,10 @@ class AnsibleModule(object):
|
||||||
|
|
||||||
def boolean(self, arg):
|
def boolean(self, arg):
|
||||||
''' return a bool for the arg '''
|
''' return a bool for the arg '''
|
||||||
|
if arg is None or type(arg) == bool:
|
||||||
|
return arg
|
||||||
if type(arg) in types.StringTypes:
|
if type(arg) in types.StringTypes:
|
||||||
arg = arg.lower()
|
arg = arg.lower()
|
||||||
|
|
||||||
if arg in BOOLEANS_TRUE:
|
if arg in BOOLEANS_TRUE:
|
||||||
return True
|
return True
|
||||||
elif arg in BOOLEANS_FALSE:
|
elif arg in BOOLEANS_FALSE:
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
|
|
||||||
SERVICE = None
|
SERVICE = None
|
||||||
CHKCONFIG = None
|
CHKCONFIG = None
|
||||||
|
INITCTL = None
|
||||||
|
|
||||||
def _find_binaries(m):
|
def _find_binaries(m):
|
||||||
# list of possible paths for service/chkconfig binaries
|
# list of possible paths for service/chkconfig binaries
|
||||||
# with the most probable first
|
# with the most probable first
|
||||||
global CHKCONFIG
|
|
||||||
global SERVICE
|
global SERVICE
|
||||||
|
global CHKCONFIG
|
||||||
global INITCTL
|
global INITCTL
|
||||||
paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin']
|
paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin']
|
||||||
binaries = [ 'service', 'chkconfig', 'update-rc.d', 'initctl']
|
binaries = [ 'service', 'chkconfig', 'update-rc.d', 'initctl']
|
||||||
|
@ -119,10 +120,11 @@ def _do_enable(name, enable):
|
||||||
valid_argument['on'] = "enable"
|
valid_argument['on'] = "enable"
|
||||||
valid_argument['off'] = "disable"
|
valid_argument['off'] = "disable"
|
||||||
|
|
||||||
if enable.lower() in ['on', 'true', 'yes', 'enable']:
|
if enable is not None:
|
||||||
rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['on']))
|
if enable:
|
||||||
elif enable.lower() in ['off', 'false', 'no', 'disable']:
|
rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['on']))
|
||||||
rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['off']))
|
else:
|
||||||
|
rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['off']))
|
||||||
|
|
||||||
return rc, stdout, stderr
|
return rc, stdout, stderr
|
||||||
|
|
||||||
|
@ -130,15 +132,14 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
name = dict(required=True),
|
name = dict(required=True),
|
||||||
state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded']),
|
state = dict(required=True, choices=['running', 'started', 'stopped', 'restarted', 'reloaded']),
|
||||||
enable = dict(choices=BOOLEANS)
|
enable = dict(choices=BOOLEANS)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
p = module.params
|
name = module.params['name']
|
||||||
name = p['name']
|
state = module.params['state']
|
||||||
state = p.get('state', None)
|
enable = module.boolean(module.params.get('enable', None))
|
||||||
enable = module.bool(p.get('enable', None))
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
# find binaries locations on minion
|
# find binaries locations on minion
|
||||||
|
|
Loading…
Add table
Reference in a new issue