Skip to content

Commit

Permalink
Omit -A and -G options in local mode since luseradd does not support …
Browse files Browse the repository at this point in the history
…these (ansible#55401)

Add integration tests
  • Loading branch information
samdoran authored and ansibot committed Jun 27, 2019
1 parent 44b6f2f commit 20ad120
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/user-local-mode-group-append.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- user - omit incompatible options when operating in local mode (https://github.com/ansible/ansible/issues/48722)
6 changes: 4 additions & 2 deletions lib/ansible/modules/system/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@
C(null), or C(~), the user is removed from all groups except the
primary group. (C(~) means C(null) in YAML)
- Before Ansible 2.3, the only input format allowed was a comma separated string.
- Has no effect when C(local) is C(True)
type: list
append:
description:
- If C(yes), add the user to the groups specified in C(groups).
- If C(no), user will only be added to the groups specified in C(groups),
removing them from all other groups.
- Has no effect when C(local) is C(True)
type: bool
default: no
shell:
Expand Down Expand Up @@ -616,7 +618,7 @@ def create_user_useradd(self):
else:
cmd.append('-N')

if self.groups is not None and len(self.groups):
if self.groups is not None and not self.local and len(self.groups):
groups = self.get_groups_set()
cmd.append('-G')
cmd.append(','.join(groups))
Expand Down Expand Up @@ -737,7 +739,7 @@ def modify_user_usermod(self):
else:
groups_need_mod = True

if groups_need_mod:
if groups_need_mod and not self.local:
if self.append and not has_append:
cmd.append('-A')
cmd.append(','.join(group_diff))
Expand Down
56 changes: 54 additions & 2 deletions test/integration/targets/user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@
state: absent
remove: yes
local: yes
register: local_user_test_3
register: local_user_test_remove_1
tags:
- user_test_local_mode

Expand All @@ -863,16 +863,68 @@
state: absent
remove: yes
local: yes
register: local_user_test_remove_2
tags:
- user_test_local_mode

- name: Create test group
group:
name: testgroup
tags:
- user_test_local_mode

- name: Create local_ansibulluser with groups
user:
name: local_ansibulluser
state: present
local: yes
groups: testgroup
register: local_user_test_3
tags:
- user_test_local_mode

- name: Create local_ansibulluser with groups again
user:
name: local_ansibulluser
state: present
local: yes
groups: testgroup
register: local_user_test_4
tags:
- user_test_local_mode

- name: Ensure local user accounts were created
- name: Remove local_ansibulluser with groups
user:
name: local_ansibulluser
state: absent
remove: yes
local: yes
groups: testgroup
register: local_user_test_remove_3
tags:
- user_test_local_mode

- name: Remove local_ansibulluser with groups again
user:
name: local_ansibulluser
state: absent
remove: yes
local: yes
groups: testgroup
register: local_user_test_remove_4
tags:
- user_test_local_mode

- name: Ensure local user accounts were created and removed properly
assert:
that:
- local_user_test_1 is changed
- local_user_test_2 is not changed
- local_user_test_3 is changed
- local_user_test_4 is not changed
- local_user_test_remove_1 is changed
- local_user_test_remove_2 is not changed
- local_user_test_remove_3 is changed
- local_user_test_remove_4 is not changed
tags:
- user_test_local_mode

0 comments on commit 20ad120

Please sign in to comment.