Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user: compare Mac user properties using same type #62973

Merged
merged 5 commits into from Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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)
4 changes: 2 additions & 2 deletions lib/ansible/modules/system/user.py
Expand Up @@ -420,7 +420,7 @@
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

Expand Down Expand Up @@ -2305,7 +2305,7 @@ def modify_user(self):
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)
Expand Down
27 changes: 27 additions & 0 deletions test/integration/targets/user/tasks/main.yml
Expand Up @@ -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:
Expand Down