Migrate apt_repository, group, and supervisorctl to use module.get_bin_path

pull/968/head
Stephen Fromm 12 years ago
parent 4c62e495eb
commit bdb39058ae

@ -26,17 +26,7 @@
import platform import platform
APT = "/usr/bin/apt-get" APT = "/usr/bin/apt-get"
ADD_APT_REPO = 'add-apt-repository'
def _find_binary(module):
binaries = ['/usr/bin/add-apt-repository']
for e in binaries:
if os.path.exists(e):
return e
module.fail_json(msg='Unabled to find any of the following executables '
'%s' % binaries)
def _run(cmd): def _run(cmd):
# returns (rc, stdout, stderr) from shell command # returns (rc, stdout, stderr) from shell command
@ -56,7 +46,10 @@ def main():
module = AnsibleModule(argument_spec=arg_spec) module = AnsibleModule(argument_spec=arg_spec)
add_apt_repository = _find_binary(module) add_apt_repository = module.get_bin_path(ADD_APT_REPO)
if add_apt_repository is None:
module.fail_json(msg='Unabled to find any of the following executables '
'%s' % binaries)
repo = module.params['repo'] repo = module.params['repo']
state = module.params['state'] state = module.params['state']

@ -21,12 +21,11 @@
import grp import grp
def get_bin_path(module, arg): def get_bin_path(module, arg):
if os.path.exists('/usr/sbin/%s' % arg): bin = module.get_bin_path(arg)
return '/usr/sbin/%s' % arg if bin is None:
elif os.path.exists('/sbin/%s' % arg):
return '/sbin/%s' % arg
else:
module.fail_json(msg="Cannot find %s" % arg) module.fail_json(msg="Cannot find %s" % arg)
else:
return bin
def group_del(module, group): def group_del(module, group):
cmd = [get_bin_path(module, 'groupdel'), group] cmd = [get_bin_path(module, 'groupdel'), group]

@ -52,7 +52,9 @@ def main():
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
SUPERVISORCTL = _find_supervisorctl() SUPERVISORCTL = module.get_bin_path('supervisorctl')
if SUPERVISORCTL is None:
module.fail_json(msg='supervisorctl is not installed')
if SUPERVISORCTL is None: if SUPERVISORCTL is None:
module.fail_json(msg='supervisorctl is not installed') module.fail_json(msg='supervisorctl is not installed')

Loading…
Cancel
Save