Fix pam_limits writing text to a file opened in binary mode

Fixes #24392
This commit is contained in:
Toshio Kuratomi 2017-05-10 15:15:43 -07:00
parent a47fbba8ae
commit 16325f6f15

View file

@ -133,9 +133,12 @@ EXAMPLES = '''
import os
import os.path
import shutil
import tempfile
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
def main():
@ -192,15 +195,15 @@ def main():
space_pattern = re.compile(r'\s+')
message = ''
f = open (limits_conf, 'r')
f = open (limits_conf, 'rb')
# Tempfile
nf = tempfile.NamedTemporaryFile()
nf = tempfile.NamedTemporaryFile(mode='w+')
found = False
new_value = value
for line in f:
line = to_native(line, errors='surrogate_or_strict')
if line.startswith('#'):
nf.write(line)
continue
@ -305,8 +308,5 @@ def main():
module.exit_json(**res_args)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()