diff --git a/changelogs/fragments/user-fix-value-comparison-on-macos.yaml b/changelogs/fragments/user-fix-value-comparison-on-macos.yaml new file mode 100644 index 00000000000..71ac1a6e396 --- /dev/null +++ b/changelogs/fragments/user-fix-value-comparison-on-macos.yaml @@ -0,0 +1,2 @@ +bugfixes: + - user - fix comprasion on macOS so module does not improperly report a change (https://github.com/ansible/ansible/issues/62969) diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index e2f86b3fdff..8849f60d050 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -420,7 +420,7 @@ import subprocess import time from ansible.module_utils import distro -from ansible.module_utils._text import to_native, to_bytes +from ansible.module_utils._text import to_bytes, to_native, to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.sys_info import get_platform_subclass @@ -2305,7 +2305,7 @@ class DarwinUser(User): for field in self.fields: if field[0] in self.__dict__ and self.__dict__[field[0]]: current = self._get_user_property(field[1]) - if current is None or current != self.__dict__[field[0]]: + if current is None or current != to_text(self.__dict__[field[0]]): cmd = self._get_dscl() cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]] (rc, _err, _out) = self.execute_command(cmd) diff --git a/test/integration/targets/user/tasks/main.yml b/test/integration/targets/user/tasks/main.yml index aef2f875542..b76531c8e02 100644 --- a/test/integration/targets/user/tasks/main.yml +++ b/test/integration/targets/user/tasks/main.yml @@ -55,6 +55,33 @@ - user_test0_1 is not changed - '"ansibulluser" in user_names.stdout_lines' +# test adding user with uid +# https://github.com/ansible/ansible/issues/62969 +- name: remove the test user + user: + name: ansibulluser + state: absent + +- name: try to create a user with uid + user: + name: ansibulluser + state: present + uid: 572 + register: user_test01_0 + +- name: create the user again + user: + name: ansibulluser + state: present + uid: 572 + register: user_test01_1 + +- name: validate results for testcase 0 + assert: + that: + - user_test01_0 is changed + - user_test01_1 is not changed + # test user add with password - name: add an encrypted password for user user: