Skip to content

Commit 3c88b13

Browse files
author
Colin Hoglund
committed
item.group takes precedence when defined
1 parent b10a464 commit 3c88b13

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The following attributes are required for each user:
3333
uid will be used
3434
* password - If a hash is provided then that will be used, but otherwise the
3535
account will be locked
36+
* group - optional primary group override
3637
* groups - a list of supplementary groups for the user.
3738
* profile - a string block for setting custom shell profiles
3839
* ssh-key - This should be a list of ssh keys for the user. Each ssh key

tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
group: name="{{item.username}}"
99
gid="{{item.gid if item.gid is defined else item.uid}}"
1010
with_items: "{{users}}"
11-
when: users_create_per_user_group
11+
when: 'group' not in item and users_create_per_user_group
1212
tags: ['users','configuration']
1313

1414
- name: User creation
1515
user:
1616
name: "{{item.username}}"
17-
group: "{{item.username if users_create_per_user_group else users_group}}"
17+
group: "{{item.group | default(item.username if users_create_per_user_group else users_group)}}"
1818
# empty string removes user from all secondary groups
1919
groups: "{{item.groups | join(',') if 'groups' in item else ''}}"
2020
shell: "{{item.shell if item.shell is defined else users_default_shell}}"
@@ -41,7 +41,7 @@
4141
block: "{{item.profile}}"
4242
dest: "{{ item.home | default('/home/' + item.username) }}/.profile"
4343
owner: "{{item.username}}"
44-
group: "{{item.username if users_create_per_user_group else users_group}}"
44+
group: "{{item.group | default(item.username if users_create_per_user_group else users_group)}}"
4545
mode: 0644
4646
create: true
4747
when: users_create_homedirs and item.profile is defined

0 commit comments

Comments
 (0)