From 16325f6f150ec09e7ca5618a9c802513bb3302a6 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 10 May 2017 15:15:43 -0700 Subject: [PATCH] Fix pam_limits writing text to a file opened in binary mode Fixes #24392 --- lib/ansible/modules/system/pam_limits.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/system/pam_limits.py b/lib/ansible/modules/system/pam_limits.py index 0e9fc8d65b..f524126744 100644 --- a/lib/ansible/modules/system/pam_limits.py +++ b/lib/ansible/modules/system/pam_limits.py @@ -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()