Fix crypttab python3 compatibility issue (#30457)

In python2 str gives byte string. In Python3 it gives unicode string so it
can't be written in a binary mode opened file.
Use to_bytes helper function to ensure content being written will be
properly encoded in both python2 and python3.
pull/21424/merge
Jonathan Piron 7 years ago committed by Toshio Kuratomi
parent e63d949951
commit 54859a2132

@ -89,7 +89,7 @@ import os
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils._text import to_bytes, to_native
def main():
@ -169,7 +169,7 @@ def main():
if changed and not module.check_mode:
try:
f = open(path, 'wb')
f.write(str(crypttab))
f.write(to_bytes(crypttab, errors='surrogate_or_strict'))
finally:
f.close()

Loading…
Cancel
Save