From 0fe99f20d9d4696b0d4428ab73a5f006c8397692 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 5 Oct 2016 14:59:02 -0700 Subject: [PATCH] Emit an error message if six is not installed. dopy 0.3.7 makes use of six but doesn't list it as a requirement. This means that people installing with pip won't get six installed, leading to errors. Upstream released dopy-0.3.7a to address that but pip thinks that is an alpha release. pip does not install alpha releases by default so users aren't helped by that. This change makes ansible emit a good error message in this case. Fixes #4613 --- .../cloud/digital_ocean/digital_ocean.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/cloud/digital_ocean/digital_ocean.py b/lib/ansible/modules/cloud/digital_ocean/digital_ocean.py index d438a3a512..5dde4e19e2 100644 --- a/lib/ansible/modules/cloud/digital_ocean/digital_ocean.py +++ b/lib/ansible/modules/cloud/digital_ocean/digital_ocean.py @@ -184,17 +184,22 @@ import traceback from distutils.version import LooseVersion -HAS_DOPY = True +try: + import six + HAS_SIX = True +except ImportError: + HAS_SIX = False + +HAS_DOPY = False try: import dopy from dopy.manager import DoError, DoManager - if LooseVersion(dopy.__version__) < LooseVersion('0.3.2'): - HAS_DOPY = False + if LooseVersion(dopy.__version__) >= LooseVersion('0.3.2'): + HAS_DOPY = True except ImportError: - HAS_DOPY = False + pass from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils._text import to_native class TimeoutError(Exception): @@ -450,15 +455,17 @@ def main(): ['id', 'name'], ), ) + if not HAS_DOPY and not HAS_SIX: + module.fail_json(msg='dopy >= 0.3.2 is required for this module. dopy requires six but six is not installed. Make sure both dopy and six are installed.') if not HAS_DOPY: module.fail_json(msg='dopy >= 0.3.2 required for this module') try: core(module) except TimeoutError as e: - module.fail_json(msg=to_native(e), id=e.id) + module.fail_json(msg=str(e), id=e.id) except (DoError, Exception) as e: - module.fail_json(msg=to_native(e), exception=traceback.format_exc()) + module.fail_json(msg=str(e), exception=traceback.format_exc()) if __name__ == '__main__': main()