diff options
author | Stephen Fromm <sfromm@gmail.com> | 2012-08-30 10:31:23 -0700 |
---|---|---|
committer | Stephen Fromm <sfromm@gmail.com> | 2012-08-30 11:01:37 -0700 |
commit | 6742e9c3f4eee72653a6b6d9f7f41fa372daec47 (patch) | |
tree | ba60eb3e564950228d25d5a265357090c5443bb2 /lib | |
parent | e5a635672c3c7e9b2f27d1ca04ddd006d61ba3ed (diff) | |
download | ansible-6742e9c3f4eee72653a6b6d9f7f41fa372daec47.tar.gz |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/module_common.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index aee5128c60..c237656441 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -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): |