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:
parent
e63d949951
commit
54859a2132
1 changed files with 2 additions and 2 deletions
|
@ -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…
Reference in a new issue