From 46f962210a4eaf8c3c42263c2cb7822ec37d3ade Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Thu, 30 Aug 2012 12:35:37 -0400 Subject: [PATCH 1/2] Move conditional that accounts for variances in distros/versions to work when removing and adding. --- apt_repository | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apt_repository b/apt_repository index 8724f7c301e..3815937f81c 100755 --- a/apt_repository +++ b/apt_repository @@ -39,6 +39,8 @@ def _find_binary(module): '%s' % binaries) def _run(cmd): + if platform.dist()[0] == 'debian' or float(platform.dist()[1]) >= 11.10: + cmd = cmd + ' -y' # returns (rc, stdout, stderr) from shell command process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -72,9 +74,6 @@ def main(): cmd = '%s "%s"' % (add_apt_repository, repo) - if platform.dist()[0] == 'debian' or float(platform.dist()[1]) >= 11.10: - cmd = cmd + ' -y' - rc, out, err = _run(cmd) changed = rc == 0 and not existed From d36d926bba8eb6ff1dd3dade329786564367e74f Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Thu, 30 Aug 2012 12:37:02 -0400 Subject: [PATCH 2/2] Update handling of state changes --- supervisorctl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/supervisorctl b/supervisorctl index 541caf1fade..9b00b6e8c84 100755 --- a/supervisorctl +++ b/supervisorctl @@ -27,6 +27,9 @@ def _find_supervisorctl(): if os.path.exists(e): return e +def _is_present(name): + rc, out, err = _run('%s status' % _find_supervisorctl()) + return name in out def _is_running(name): rc, out, err = _run('%s status %s' % (_find_supervisorctl(), name)) @@ -44,7 +47,7 @@ def _run(cmd): def main(): arg_spec = dict( name=dict(required=True), - state=dict(required=True, choices=['started', 'restarted', 'stopped']) + state=dict(required=True, choices=['present', 'started', 'restarted', 'stopped']) ) module = AnsibleModule(argument_spec=arg_spec) @@ -57,6 +60,20 @@ def main(): if SUPERVISORCTL is None: module.fail_json(msg='supervisorctl is not installed') + present = _is_present(name) + + if state == 'present': + if not present: + _run('%s reread' % SUPERVISORCTL) + rc, out, err = _run('%s add %s' % (SUPERVISORCTL, name)) + + if '%s: added process group' % name in out: + module.exit_json(changed=True, name=name, state=state) + else: + module.fail_json(msg=out, name=name, state=state) + + module.exit_json(changed=False, name=name, state=state) + running = _is_running(name) if running and state == 'started': @@ -71,7 +88,7 @@ def main(): module.fail_json(msg=out) elif running and state == 'restarted': - rc, out, err = _run('%s update' % SUPERVISORCTL) + rc, out, err = _run('%s update %s' % (SUPERVISORCTL, name)) rc, out, err = _run('%s restart %s' % (SUPERVISORCTL, name)) if '%s: stopped' % name in out and '%s: started' % name in out: @@ -80,7 +97,6 @@ def main(): module.fail_json(msg=out) elif not running and state == 'started': - rc, out, err = _run('%s update' % SUPERVISORCTL) rc, out, err = _run('%s start %s' % (SUPERVISORCTL, name)) if '%s: started' % name in out: