user - compare macOS user properties using same type (#62973)
self._get_user_property returns a string, so when doing a comparison using this value, cast the second variable to a string so that the comparison behaves correctly * Add changelog * Add to_text import * Add integration test
This commit is contained in:
parent
d4c4c92c97
commit
c73288ad53
3 changed files with 31 additions and 2 deletions
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue