diff options
author | Deepak Agrawal <deepacks@gmail.com> | 2018-11-09 06:48:21 +0530 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2018-11-08 17:18:21 -0800 |
commit | 71ee1adf0ba309504b3fa7c0264400490b4a22cf (patch) | |
tree | 99f99d62036e84ded628c291562b6ea3cd0f5df2 | |
parent | b000c1633dc5b9bba0bc7f51376d9172b46a8feb (diff) | |
download | ansible-71ee1adf0ba309504b3fa7c0264400490b4a22cf.tar.gz |
Backport/2.7/48148: net_put module leaves empty files behind (#48151)
* cleanp net_put temp file (#48148)
(cherry picked from commit d2c7665be9965a82f14dab91248a78ed7def9c2d)
* add changelog entry
-rw-r--r-- | changelogs/fragments/48148_net_put_cleanup.yaml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/action/net_put.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/changelogs/fragments/48148_net_put_cleanup.yaml b/changelogs/fragments/48148_net_put_cleanup.yaml new file mode 100644 index 0000000000..a9d7d65ec6 --- /dev/null +++ b/changelogs/fragments/48148_net_put_cleanup.yaml @@ -0,0 +1,2 @@ +bugfixes: +- "net_put - fix when net_put module leaves temp files in some network OS cases e.g. routerOS" diff --git a/lib/ansible/plugins/action/net_put.py b/lib/ansible/plugins/action/net_put.py index 30fa7dff92..d71bcbfd3a 100644 --- a/lib/ansible/plugins/action/net_put.py +++ b/lib/ansible/plugins/action/net_put.py @@ -23,6 +23,7 @@ import time import uuid import hashlib import sys +import re from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.connection import Connection @@ -148,7 +149,11 @@ class ActionModule(ActionBase): proto=proto, timeout=timeout ) except Exception as exc: - if (to_text(exc)).find("No such file or directory") > 0: + pattern = to_text(exc) + not_found_exc = "No such file or directory" + if re.search(not_found_exc, pattern, re.I): + if os.path.exists(source_file): + os.remove(source_file) return True else: try: @@ -162,6 +167,7 @@ class ActionModule(ActionBase): with open(source_file, 'r') as f: old_content = f.read() except (IOError, OSError) as ioexc: + os.remove(source_file) raise IOError(ioexc) sha1 = hashlib.sha1() |