Skip to content

Commit

Permalink
Only report change when home directory is different on FreeBSD (ansib…
Browse files Browse the repository at this point in the history
…le#42865)

* Only report change when home directory is different

Add tests with home: parameter

Have to skip macOS for now since there is a bug when specifying the home directory path for an existing user that results in a module failure. That needs to be fixed in a separate PR.
  • Loading branch information
samdoran authored Jul 19, 2018
1 parent 786613f commit 0ca61e9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/user_freebsd_always_changed_bugfix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- user - fix bug that resulted in module always reporting a change when specifiying the home directory on FreeBSD (https://github.com/ansible/ansible/issues/42484)
5 changes: 3 additions & 2 deletions lib/ansible/modules/system/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,9 @@ def modify_user(self):
if self.home is not None:
if (info[5] != self.home and self.move_home) or (not os.path.exists(self.home) and self.create_home):
cmd.append('-m')
cmd.append('-d')
cmd.append(self.home)
if info[5] != self.home:
cmd.append('-d')
cmd.append(self.home)

if self.skeleton is not None:
cmd.append('-k')
Expand Down
53 changes: 50 additions & 3 deletions test/integration/targets/user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
user:
name: ansibulluser
state: present
register: user_test0
register: user_test0_0

- name: create the user again
user:
name: ansibulluser
state: present
register: user_test0_1

- debug:
var: user_test0
Expand All @@ -54,9 +60,50 @@
- name: validate results for testcase 0
assert:
that:
- user_test0 is changed
- user_test0_0 is changed
- user_test0_1 is not changed
- '"ansibulluser" in user_names.stdout_lines'

# https://github.com/ansible/ansible/issues/42484
# Skipping macOS for now since there is a bug when changing home directory
- block:
- name: create user specifying home
user:
name: ansibulluser
state: present
home: "{{ user_home_prefix[ansible_system] }}/ansibulluser"
register: user_test3_0

- name: create user again specifying home
user:
name: ansibulluser
state: present
home: "{{ user_home_prefix[ansible_system] }}/ansibulluser"
register: user_test3_1

- name: change user home
user:
name: ansibulluser
state: present
home: "{{ user_home_prefix[ansible_system] }}/ansibulluser-mod"
register: user_test3_2

- name: change user home back
user:
name: ansibulluser
state: present
home: "{{ user_home_prefix[ansible_system] }}/ansibulluser"
register: user_test3_3

- name: validate results for testcase 3
assert:
that:
- user_test3_0 is not changed
- user_test3_1 is not changed
- user_test3_2 is changed
- user_test3_3 is changed
when: ansible_system != 'Darwin'


## user check

Expand All @@ -65,7 +112,7 @@
name: "{{ user_names.stdout_lines | random }}"
state: present
create_home: no
with_sequence: start=1 end=5
loop: "{{ range(1, 5+1) | list }}"
register: user_test1

- debug:
Expand Down
5 changes: 5 additions & 0 deletions test/integration/targets/user/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
user_home_prefix:
Linux: '/home'
FreeBSD: '/home'
SunOS: '/home'
Darwin: '/Users'

0 comments on commit 0ca61e9

Please sign in to comment.