mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 05:12:45 +00:00
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.
This commit is contained in:
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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user