lineinfile - fix broken exception handling (#70846)
* prevent (ExceptionType) is not subscriptable errors * tweak error message and use text conversion * add to_text import
This commit is contained in:
parent
be4be926c4
commit
45c2eb6c0a
2 changed files with 4 additions and 2 deletions
2
changelogs/fragments/lineinfile_exc_fix.yml
Normal file
2
changelogs/fragments/lineinfile_exc_fix.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- lineinfile - fix not subscriptable error in exception handling around file creation
|
|
@ -212,7 +212,7 @@ import tempfile
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_bytes, to_native
|
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||||
|
|
||||||
|
|
||||||
def write_changes(module, b_lines, dest):
|
def write_changes(module, b_lines, dest):
|
||||||
|
@ -267,7 +267,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
|
||||||
try:
|
try:
|
||||||
os.makedirs(b_destpath)
|
os.makedirs(b_destpath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg='Error creating %s Error code: %s Error description: %s' % (b_destpath, e[0], e[1]))
|
module.fail_json(msg='Error creating %s (%s)' % (to_text(b_destpath), to_text(e)))
|
||||||
|
|
||||||
b_lines = []
|
b_lines = []
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue