mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-07 08:54:01 -07:00
Use common functions for handling import errors (#51851)
* Use common functions for handling import errors * use refactored version of gitlab modules
This commit is contained in:
parent
28dcfa985f
commit
c1e51ef486
39 changed files with 233 additions and 93 deletions
|
@ -140,17 +140,20 @@ EXAMPLES = '''
|
|||
RETURN = r"""# """
|
||||
|
||||
import os
|
||||
import traceback
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
DNSIMPLE_IMP_ERR = None
|
||||
try:
|
||||
from dnsimple import DNSimple
|
||||
from dnsimple.dnsimple import __version__ as dnsimple_version
|
||||
from dnsimple.dnsimple import DNSimpleException
|
||||
HAS_DNSIMPLE = True
|
||||
except ImportError:
|
||||
DNSIMPLE_IMP_ERR = traceback.format_exc()
|
||||
HAS_DNSIMPLE = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -176,7 +179,7 @@ def main():
|
|||
)
|
||||
|
||||
if not HAS_DNSIMPLE:
|
||||
module.fail_json(msg="dnsimple required for this module")
|
||||
module.fail_json(msg=missing_required_lib('dnsimple'), exception=DNSIMPLE_IMP_ERR)
|
||||
|
||||
if LooseVersion(dnsimple_version) < LooseVersion('1.0.0'):
|
||||
module.fail_json(msg="Current version of dnsimple Python module [%s] uses 'v1' API which is deprecated."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue