mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Add option required=(True|False) to get_bin_path and update modules
Added required as optional argument to get_bin_path(). It defaults to false. Updated following modules to use required=True when calling get_bin_path(): apt_repository, easy_install, group, pip, supervisorctl, and user. Also removed _find_supervisorctl() from supervisorctl module and updated _is_running() to not need it.
This commit is contained in:
parent
e5a635672c
commit
6742e9c3f4
7 changed files with 21 additions and 49 deletions
|
@ -202,9 +202,12 @@ class AnsibleModule(object):
|
|||
log_args = re.sub(r'login_password=.+ (.*)', r"login_password=NOT_LOGGING_PASSWORD \1", log_args)
|
||||
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % log_args)
|
||||
|
||||
def get_bin_path(self, arg, opt_dirs=[]):
|
||||
def get_bin_path(self, arg, required=False, opt_dirs=[]):
|
||||
'''
|
||||
find system executable in PATH.
|
||||
Optional arguments:
|
||||
- required: if executable is not found and required is true, fail_json
|
||||
- opt_dirs: optional list of directories to search in addition to PATH
|
||||
if found return full path; otherwise return None
|
||||
'''
|
||||
sbin_paths = ['/sbin', '/usr/sbin', '/usr/local/sbin']
|
||||
|
@ -223,6 +226,8 @@ class AnsibleModule(object):
|
|||
if os.path.exists(path) and os.access(path, os.X_OK):
|
||||
bin_path = path
|
||||
break
|
||||
if required and bin_path is None:
|
||||
self.fail_json(msg='Failed to find required executable %s' % arg)
|
||||
return bin_path
|
||||
|
||||
def boolean(self, arg):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue