assemble: avoid extra newline on Python 3 (#54176)

Fixes #44739
This commit is contained in:
Martin Krizek 2019-03-22 15:14:02 +01:00 committed by Matt Martz
parent 1e6aa9533c
commit 63ea96d5f1
2 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- assemble - avoid extra newline on Python 3 (https://github.com/ansible/ansible/issues/44739)

View file

@ -116,7 +116,7 @@ import re
import tempfile
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import b
from ansible.module_utils.six import b, indexbytes
from ansible.module_utils._text import to_native
@ -148,7 +148,11 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, igno
tmp.write(delimiter)
# always make sure there's a newline after the
# delimiter, so lines don't run together
if delimiter[-1] != b('\n'):
# byte indexing differs on Python 2 and 3,
# use indexbytes for compat
# chr(10) == '\n'
if indexbytes(delimiter, -1) != 10:
tmp.write(b('\n'))
tmp.write(fragment_content)