diff --git a/lib/ansible/modules/extras/packaging/language/maven_artifact.py b/lib/ansible/modules/extras/packaging/language/maven_artifact.py index f529518545..1a33d1b989 100644 --- a/lib/ansible/modules/extras/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/extras/packaging/language/maven_artifact.py @@ -26,6 +26,8 @@ import os import hashlib import sys import posixpath +from ansible.module_utils.basic import * +from ansible.module_utils.urls import * DOCUMENTATION = ''' --- @@ -330,7 +332,7 @@ def main(): try: artifact = Artifact(group_id, artifact_id, version, classifier, extension) - except ValueError, e: + except ValueError as e: module.fail_json(msg=e.args[0]) prev_state = "absent" @@ -351,12 +353,10 @@ def main(): module.exit_json(state=state, dest=dest, group_id=group_id, artifact_id=artifact_id, version=version, classifier=classifier, extension=extension, repository_url=repository_url, changed=True) else: module.fail_json(msg="Unable to download the artifact") - except ValueError, e: + except ValueError as e: module.fail_json(msg=e.args[0]) -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * + if __name__ == '__main__': main() diff --git a/lib/ansible/modules/extras/packaging/os/layman.py b/lib/ansible/modules/extras/packaging/os/layman.py index f9ace12120..ac6acd12d4 100644 --- a/lib/ansible/modules/extras/packaging/os/layman.py +++ b/lib/ansible/modules/extras/packaging/os/layman.py @@ -120,7 +120,7 @@ def download_url(module, url, dest): try: with open(dest, 'w') as f: shutil.copyfileobj(response, f) - except IOError, e: + except IOError as e: raise ModuleError("Failed to write: %s" % str(e)) @@ -248,7 +248,7 @@ def main(): else: changed = uninstall_overlay(module, name) - except ModuleError, e: + except ModuleError as e: module.fail_json(msg=e.message) else: module.exit_json(changed=changed, name=name) diff --git a/lib/ansible/modules/extras/packaging/os/yum_repository.py b/lib/ansible/modules/extras/packaging/os/yum_repository.py index 89de7eb381..27e4c83d4a 100644 --- a/lib/ansible/modules/extras/packaging/os/yum_repository.py +++ b/lib/ansible/modules/extras/packaging/os/yum_repository.py @@ -21,6 +21,7 @@ import ConfigParser import os +from ansible.module_utils.pycompat24 import get_exception DOCUMENTATION = ''' @@ -575,7 +576,8 @@ class YumRepo(object): # Write data into the file try: fd = open(self.params['dest'], 'wb') - except IOError, e: + except IOError: + e = get_exception() self.module.fail_json( msg="Cannot open repo file %s." % self.params['dest'], details=str(e)) @@ -584,7 +586,8 @@ class YumRepo(object): try: fd.close() - except IOError, e: + except IOError: + e = get_exception() self.module.fail_json( msg="Cannot write repo file %s." % self.params['dest'], details=str(e)) @@ -592,7 +595,8 @@ class YumRepo(object): # Remove the file if there are not repos try: os.remove(self.params['dest']) - except OSError, e: + except OSError: + e = get_exception() self.module.fail_json( msg=( "Cannot remove empty repo file %s." %