diff options
author | Matt Clay <matt@mystile.com> | 2022-03-02 10:29:32 -0800 |
---|---|---|
committer | Matt Clay <matt@mystile.com> | 2022-03-02 11:34:11 -0800 |
commit | 6de04e8be6c9cfbc9776898a67b18a41bf1469d5 (patch) | |
tree | 8290b2edb4a70ed569f2f9556e1e44908a2f4ea9 /lib/ansible/modules | |
parent | d31730d78129d223d0611e2f62561e52bd019e09 (diff) | |
download | ansible-6de04e8be6c9cfbc9776898a67b18a41bf1469d5.tar.gz |
Fix module exception handlers.
Exception handler variable names should not conflict with other variables.
Use Python 2.6+ exception handler syntax.
Diffstat (limited to 'lib/ansible/modules')
-rw-r--r-- | lib/ansible/modules/apt_repository.py | 16 | ||||
-rw-r--r-- | lib/ansible/modules/async_wrapper.py | 3 |
2 files changed, 9 insertions, 10 deletions
diff --git a/lib/ansible/modules/apt_repository.py b/lib/ansible/modules/apt_repository.py index eb0c1a50c1..a4b5023af7 100644 --- a/lib/ansible/modules/apt_repository.py +++ b/lib/ansible/modules/apt_repository.py @@ -311,9 +311,9 @@ class SourcesList(object): d, fn = os.path.split(filename) try: os.makedirs(d) - except OSError as err: + except OSError as ex: if not os.path.isdir(d): - self.module.fail_json("Failed to create directory %s: %s" % (d, to_native(err))) + self.module.fail_json("Failed to create directory %s: %s" % (d, to_native(ex))) fd, tmp_path = tempfile.mkstemp(prefix=".%s-" % fn, dir=d) f = os.fdopen(fd, 'w') @@ -330,8 +330,8 @@ class SourcesList(object): try: f.write(line) - except IOError as err: - self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, to_native(err))) + except IOError as ex: + self.module.fail_json(msg="Failed to write to file %s: %s" % (tmp_path, to_native(ex))) self.module.atomic_move(tmp_path, filename) # allow the user to override the default mode @@ -613,8 +613,8 @@ def main(): sourceslist.add_source(repo) elif state == 'absent': sourceslist.remove_source(repo) - except InvalidSource as err: - module.fail_json(msg='Invalid repository string: %s' % to_native(err)) + except InvalidSource as ex: + module.fail_json(msg='Invalid repository string: %s' % to_native(ex)) sources_after = sourceslist.dump() changed = sources_before != sources_after @@ -655,9 +655,9 @@ def main(): revert_sources_list(sources_before, sources_after, sourceslist_before) module.fail_json(msg='Failed to update apt cache: %s' % (err if err else 'unknown reason')) - except (OSError, IOError) as err: + except (OSError, IOError) as ex: revert_sources_list(sources_before, sources_after, sourceslist_before) - module.fail_json(msg=to_native(err)) + module.fail_json(msg=to_native(ex)) module.exit_json(changed=changed, repo=repo, state=state, diff=diff) diff --git a/lib/ansible/modules/async_wrapper.py b/lib/ansible/modules/async_wrapper.py index dd6bb5b73f..7eea4c14f6 100644 --- a/lib/ansible/modules/async_wrapper.py +++ b/lib/ansible/modules/async_wrapper.py @@ -342,8 +342,7 @@ def main(): _run_module(cmd, jid) notice("Module complete (%s)" % os.getpid()) - except Exception: - e = sys.exc_info()[1] + except Exception as e: notice("error: %s" % e) end({"failed": True, "msg": "FATAL ERROR: %s" % e}, "async_wrapper exited prematurely") |