call to_text on full config file
fixes issue #30571
(cherry picked from commit 0a114436fc14fc9eb5ec0ff9d42400beb3c63c60)
... | ... |
@@ -438,6 +438,7 @@ else: |
438 | 438 |
from ansible.module_utils.basic import AnsibleModule |
439 | 439 |
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE |
440 | 440 |
from ansible.module_utils.six.moves import xrange |
441 |
+from ansible.module_utils._text import to_text, to_bytes |
|
441 | 442 |
|
442 | 443 |
|
443 | 444 |
# LXC_COMPRESSION_MAP is a map of available compression types when creating |
... | ... |
@@ -572,7 +573,7 @@ def create_script(command): |
572 | 572 |
(fd, script_file) = tempfile.mkstemp(prefix='lxc-attach-script') |
573 | 573 |
f = os.fdopen(fd, 'wb') |
574 | 574 |
try: |
575 |
- f.write(ATTACH_TEMPLATE % {'container_command': command}) |
|
575 |
+ f.write(to_bytes(ATTACH_TEMPLATE % {'container_command': command}, errors='surrogate_or_strict')) |
|
576 | 576 |
f.flush() |
577 | 577 |
finally: |
578 | 578 |
f.close() |
... | ... |
@@ -724,7 +725,7 @@ class LxcContainerManagement(object): |
724 | 724 |
|
725 | 725 |
container_config_file = self.container.config_file_name |
726 | 726 |
with open(container_config_file, 'rb') as f: |
727 |
- container_config = f.readlines() |
|
727 |
+ container_config = to_text(f.read(), errors='surrogate_or_strict').splitlines() |
|
728 | 728 |
|
729 | 729 |
# Note used ast literal_eval because AnsibleModule does not provide for |
730 | 730 |
# adequate dictionary parsing. |
... | ... |
@@ -765,7 +766,7 @@ class LxcContainerManagement(object): |
765 | 765 |
self.container.stop() |
766 | 766 |
|
767 | 767 |
with open(container_config_file, 'wb') as f: |
768 |
- f.writelines(container_config) |
|
768 |
+ f.writelines([to_bytes(line, errors='surrogate_or_strict') for line in container_config]) |
|
769 | 769 |
|
770 | 770 |
self.state_change = True |
771 | 771 |
if container_state == 'running': |