Repository: ansible/ansible

Issue:
Py3 error, modify pass failed with """'str' does not support the buffer interface"""
https://github.com/ansible/ansible/blob/09cabaf702bab81d2d4abd9b0f81913b5b033921/lib/ansible/modules/system/user.py#L1459

example failed output:
"""
fatal: [calgtnt04]: FAILED! => {"changed": false, "failed": true, "msg": "failed to update users password: 'str' does not support the buffer interface"}
"""

This host is SunOS  10u11
working on testing change to open file with 'wb+'.
Py3 error, modify pass failed with """'str' does not support the buffer interface"""
https://github.com/ansible/ansible/blob/09cabaf702bab81d2d4abd9b0f81913b5b033921/lib/ansible/modules/system/user.py#L1459

example failed output:
"""
fatal: [calgtnt04]: FAILED! => {"changed": false, "failed": true, "msg": "failed to update users password: 'str' does not support the buffer interface"}
"""

This host is SunOS  10u11
working on testing change to open file with 'wb+'.


Discussion:
@c0psrul3 Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- issue type
- ansible version
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
Issue type is Bug  and appears to be similar to #19715
Affecting User module in  Ansible v2.3.1 , v2.3.2 , devel
@c0psrul3 Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- issue type
- ansible version
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
Issue type is Bug  and appears to be similar to #19715
Affecting User module in  Ansible v2.3.1 , v2.3.2 , devel

Resolving patch:
diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py
--- a/lib/ansible/modules/system/user.py
+++ b/lib/ansible/modules/system/user.py
@@ -1348,6 +1348,7 @@ def create_user(self):
                 try:
                     lines = []
                     for line in open(self.SHADOWFILE, 'rb').readlines():
+                        line = to_native(line, errors='surrogate_or_strict')
                         fields = line.strip().split(':')
                         if not fields[0] == self.name:
                             lines.append(line)
@@ -1442,6 +1443,7 @@ def modify_user_usermod(self):
                 try:
                     lines = []
                     for line in open(self.SHADOWFILE, 'rb').readlines():
+                        line = to_native(line, errors='surrogate_or_strict')
                         fields = line.strip().split(':')
                         if not fields[0] == self.name:
                             lines.append(line)


Test patch: