Add helper function to return helpful import error msg (#47409)

This commit is contained in:
Jordan Borean 2018-10-24 07:21:36 +10:00 committed by GitHub
parent f28b7c7ab1
commit ddfd1dbfc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 15 deletions

View file

@ -321,10 +321,9 @@ rc:
sample: 0
'''
import sys
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils._text import to_bytes, to_text
PYPSEXEC_IMP_ERR = None
@ -407,9 +406,7 @@ def main():
'running as System: process_username, '
'process_password')
if not HAS_PYPSEXEC:
module.fail_json(msg="The pypsexec Python module is required to be "
"installed for the Python environment at '%s'"
% sys.executable,
module.fail_json(msg=missing_required_lib("pypsexec"),
exception=PYPSEXEC_IMP_ERR)
hostname = module.params['hostname']
@ -443,11 +440,8 @@ def main():
if connection_username is None or connection_password is None and \
not HAS_KERBEROS:
module.fail_json(msg="The gssapi Python module with the GGF extension "
"used for kerberos auth is required to be "
"installed for the Python environment at '%s'"
% sys.executable,
exception=KERBEROS_IMP_ERR)
module.fail_json(msg=missing_required_lib("gssapi"),
execption=KERBEROS_IMP_ERR)
win_client = client.Client(server=hostname, username=connection_username,
password=connection_password, port=port,