|
|
|
@ -87,6 +87,8 @@ EXAMPLES = '''
|
|
|
|
|
|
|
|
|
|
import platform
|
|
|
|
|
import shlex
|
|
|
|
|
from ansible.module_utils.pycompat24 import get_exception
|
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
|
|
|
|
|
|
def _load_dist_subclass(cls, *args, **kwargs):
|
|
|
|
|
'''
|
|
|
|
@ -152,7 +154,8 @@ class Svc(object):
|
|
|
|
|
if os.path.exists(self.src_full):
|
|
|
|
|
try:
|
|
|
|
|
os.symlink(self.src_full, self.svc_full)
|
|
|
|
|
except OSError, e:
|
|
|
|
|
except OSError:
|
|
|
|
|
e = get_exception()
|
|
|
|
|
self.module.fail_json(path=self.src_full, msg='Error while linking: %s' % str(e))
|
|
|
|
|
else:
|
|
|
|
|
self.module.fail_json(msg="Could not find source for service to enable (%s)." % self.src_full)
|
|
|
|
@ -160,7 +163,8 @@ class Svc(object):
|
|
|
|
|
def disable(self):
|
|
|
|
|
try:
|
|
|
|
|
os.unlink(self.svc_full)
|
|
|
|
|
except OSError, e:
|
|
|
|
|
except OSError:
|
|
|
|
|
e = get_exception()
|
|
|
|
|
self.module.fail_json(path=self.svc_full, msg='Error while unlinking: %s' % str(e))
|
|
|
|
|
self.execute_command([self.svc_cmd,'-dx',self.src_full])
|
|
|
|
|
|
|
|
|
@ -221,7 +225,8 @@ class Svc(object):
|
|
|
|
|
def execute_command(self, cmd):
|
|
|
|
|
try:
|
|
|
|
|
(rc, out, err) = self.module.run_command(' '.join(cmd))
|
|
|
|
|
except Exception, e:
|
|
|
|
|
except Exception:
|
|
|
|
|
e = get_exception()
|
|
|
|
|
self.module.fail_json(msg="failed to execute: %s" % str(e))
|
|
|
|
|
return (rc, out, err)
|
|
|
|
|
|
|
|
|
@ -267,7 +272,8 @@ def main():
|
|
|
|
|
svc.enable()
|
|
|
|
|
else:
|
|
|
|
|
svc.disable()
|
|
|
|
|
except (OSError, IOError), e:
|
|
|
|
|
except (OSError, IOError):
|
|
|
|
|
e = get_exception()
|
|
|
|
|
module.fail_json(msg="Could change service link: %s" % str(e))
|
|
|
|
|
|
|
|
|
|
if state is not None and state != svc.state:
|
|
|
|
@ -284,13 +290,13 @@ def main():
|
|
|
|
|
open(d_file, "a").close()
|
|
|
|
|
else:
|
|
|
|
|
os.unlink(d_file)
|
|
|
|
|
except (OSError, IOError), e:
|
|
|
|
|
except (OSError, IOError):
|
|
|
|
|
e = get_exception()
|
|
|
|
|
module.fail_json(msg="Could change downed file: %s " % (str(e)))
|
|
|
|
|
|
|
|
|
|
module.exit_json(changed=changed, svc=svc.report())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# this is magic, not normal python include
|
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main()
|
|
|
|
|