1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

lxc_container: open files as text, fixes #30571 (#30572)

call to_text on full config file

fixes issue #30571
This commit is contained in:
bit 2017-09-28 05:32:45 +02:00 committed by Toshio Kuratomi
parent c6a676c025
commit 0a114436fc

View file

@ -438,6 +438,7 @@ else:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
from ansible.module_utils.six.moves import xrange
from ansible.module_utils._text import to_text, to_bytes
# LXC_COMPRESSION_MAP is a map of available compression types when creating
@ -572,7 +573,7 @@ def create_script(command):
(fd, script_file) = tempfile.mkstemp(prefix='lxc-attach-script')
f = os.fdopen(fd, 'wb')
try:
f.write(ATTACH_TEMPLATE % {'container_command': command})
f.write(to_bytes(ATTACH_TEMPLATE % {'container_command': command}, errors='surrogate_or_strict'))
f.flush()
finally:
f.close()
@ -722,7 +723,7 @@ class LxcContainerManagement(object):
container_config_file = self.container.config_file_name
with open(container_config_file, 'rb') as f:
container_config = f.readlines()
container_config = to_text(f.read(), errors='surrogate_or_strict').splitlines()
# Note used ast literal_eval because AnsibleModule does not provide for
# adequate dictionary parsing.
@ -763,7 +764,7 @@ class LxcContainerManagement(object):
self.container.stop()
with open(container_config_file, 'wb') as f:
f.writelines(container_config)
f.writelines([to_bytes(line, errors='surrogate_or_strict') for line in container_config])
self.state_change = True
if container_state == 'running':