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
This commit is contained in:
parent
064c381608
commit
0fe99f20d9
1 changed files with 14 additions and 7 deletions
|
@ -184,17 +184,22 @@ import traceback
|
||||||
|
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
|
||||||
HAS_DOPY = True
|
try:
|
||||||
|
import six
|
||||||
|
HAS_SIX = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_SIX = False
|
||||||
|
|
||||||
|
HAS_DOPY = False
|
||||||
try:
|
try:
|
||||||
import dopy
|
import dopy
|
||||||
from dopy.manager import DoError, DoManager
|
from dopy.manager import DoError, DoManager
|
||||||
if LooseVersion(dopy.__version__) < LooseVersion('0.3.2'):
|
if LooseVersion(dopy.__version__) >= LooseVersion('0.3.2'):
|
||||||
HAS_DOPY = False
|
HAS_DOPY = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_DOPY = False
|
pass
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_native
|
|
||||||
|
|
||||||
|
|
||||||
class TimeoutError(Exception):
|
class TimeoutError(Exception):
|
||||||
|
@ -450,15 +455,17 @@ def main():
|
||||||
['id', 'name'],
|
['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:
|
if not HAS_DOPY:
|
||||||
module.fail_json(msg='dopy >= 0.3.2 required for this module')
|
module.fail_json(msg='dopy >= 0.3.2 required for this module')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
core(module)
|
core(module)
|
||||||
except TimeoutError as e:
|
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:
|
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__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue