mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Migrate apt_repository, group, and supervisorctl to use module.get_bin_path
This commit is contained in:
parent
4c62e495eb
commit
bdb39058ae
3 changed files with 12 additions and 18 deletions
|
@ -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']
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue