From a284228e10bf2ba9d83117ce500eb0d53f5d57ea Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Tue, 21 Aug 2012 07:36:38 -0700 Subject: [PATCH] Migrate apt_repository, group, and supervisorctl to use module.get_bin_path --- apt_repository | 17 +++++------------ group | 9 ++++----- supervisorctl | 4 +++- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/apt_repository b/apt_repository index 8724f7c301e..e5d8d46c5f2 100755 --- a/apt_repository +++ b/apt_repository @@ -26,17 +26,7 @@ import platform APT = "/usr/bin/apt-get" - - -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) +ADD_APT_REPO = 'add-apt-repository' def _run(cmd): # returns (rc, stdout, stderr) from shell command @@ -56,7 +46,10 @@ def main(): 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'] state = module.params['state'] diff --git a/group b/group index 23e8703c496..d4c160ebb5d 100755 --- a/group +++ b/group @@ -21,12 +21,11 @@ import grp def get_bin_path(module, arg): - if os.path.exists('/usr/sbin/%s' % arg): - return '/usr/sbin/%s' % arg - elif os.path.exists('/sbin/%s' % arg): - return '/sbin/%s' % arg - else: + bin = module.get_bin_path(arg) + if bin is None: module.fail_json(msg="Cannot find %s" % arg) + else: + return bin def group_del(module, group): cmd = [get_bin_path(module, 'groupdel'), group] diff --git a/supervisorctl b/supervisorctl index 541caf1fade..e0671a5869b 100755 --- a/supervisorctl +++ b/supervisorctl @@ -52,7 +52,9 @@ def main(): name = module.params['name'] 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: module.fail_json(msg='supervisorctl is not installed')