mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Add helper function to return helpful import error msg (#47409)
This commit is contained in:
@@ -785,6 +785,12 @@ def jsonify(data, **kwargs):
|
||||
raise UnicodeError('Invalid unicode encoding encountered')
|
||||
|
||||
|
||||
def missing_required_lib(library):
|
||||
hostname = platform.node()
|
||||
return "Failed to import the required Python library (%s) on %s's Python %s. Please read module documentation " \
|
||||
"and install in the appropriate location." % (library, hostname, sys.executable)
|
||||
|
||||
|
||||
class AnsibleFallbackNotFound(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user