Skip to content

Commit 58fdd69

Browse files
author
Colin Hoglund
authored
Merge pull request #42 from singleplatform-eng/allow_individual_primary_group_overrides
Allow individual primary group overrides
2 parents b10a464 + f4e0a18 commit 58fdd69

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

.travis.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,21 @@ script:
2727
# its a big thing to bring in on a small pull.
2828
- id ansibletestuser | grep --silent "uid=2222(ansibletestuser) gid=2222(ansibletestuser) groups=2222(ansibletestuser),2(bin),100(users)"
2929
- id ansibletestuser2 | grep --silent "uid=2223(ansibletestuser2) gid=2223(ansibletestuser2) groups=2223(ansibletestuser2),2(bin),100(users)"
30-
- id ansibletestuser3 | grep --silent "uid=2224(ansibletestuser3) gid=4000(ansibletestgroup) groups=4000(ansibletestgroup),2(bin),100(users)"
30+
- id ansibletestuser3 | grep --silent "uid=2224(ansibletestuser3) gid=4001(ansibletestgroup1) groups=4001(ansibletestgroup1),2(bin),100(users)"
3131
- id ansibletestuser4 | grep --silent "uid=2225(ansibletestuser4) gid=100(users) groups=100(users),2(bin)"
32+
- id ansibletestuser5 | grep --silent "uid=2226(ansibletestuser5) gid=4000(ansibletestgroup) groups=4000(ansibletestgroup),2(bin),100(users)"
3233
- grep --silent "^ansibletestgroup:" /etc/group
3334
- grep --silent "^ansibletestgroup1:" /etc/group
3435
- ls -lgd /home/ansibletestuser | awk '{exit $3!="ansibletestuser"}'
3536
- ls -lgd /home/otherdirectory | awk '{exit $3!="ansibletestuser2"}'
36-
- ls -lgd /home/ansibletestuser3 | awk '{exit $3!="ansibletestgroup"}'
37+
- ls -lgd /home/ansibletestuser3 | awk '{exit $3!="ansibletestgroup1"}'
3738
- ls -lgd /home/otherdirectory1 | awk '{exit $3!="users"}'
38-
- ls -lg /home/ansibletestuser/.profile | awk '{exit $3!="ansibletestuser"}'
39-
- ls -lg /home/otherdirectory/.profile | awk '{exit $3!="ansibletestuser2"}'
40-
- ls -lg /home/ansibletestuser3/.profile | awk '{exit $3!="ansibletestgroup"}'
41-
- ls -lg /home/otherdirectory1/.profile | awk '{exit $3!="users"}'
39+
- ls -lgd /home/ansibletestuser5 | awk '{exit $3!="ansibletestgroup"}'
40+
- ls -lg /home/ansibletestuser/.profile | awk '{exit $3!="ansibletestuser"}'
41+
- ls -lg /home/otherdirectory/.profile | awk '{exit $3!="ansibletestuser2"}'
42+
- ls -lg /home/ansibletestuser3/.profile | awk '{exit $3!="ansibletestgroup1"}'
43+
- ls -lg /home/otherdirectory1/.profile | awk '{exit $3!="users"}'
44+
- ls -lgd /home/ansibletestuser5/.profile | awk '{exit $3!="ansibletestgroup"}'
4245

4346
notifications:
4447
webhooks: https://galaxy.ansible.com/api/v1/notifications/

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

tests/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,22 @@
8484

8585
roles:
8686
- ansible-users
87+
88+
- hosts: localhost
89+
remote_user: root
90+
vars:
91+
users:
92+
- name: Ansible Test User5
93+
username: ansibletestuser5
94+
uid: 2226
95+
group: ansibletestgroup
96+
groups: [users, bin]
97+
shell: /bin/sh
98+
profile: |
99+
alias ll='ls -lah'
100+
alias cp='cp -iv'
101+
ssh_key:
102+
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVpUJQCOaPg3p5xro9e+1fkGRWNOGrrExiKMqTE91Fwu349bxfMnMzRS0PAERouR9EEL+Ee4Yzhav/uNc35eCtXzACtluXnAncMrQj6pM3IqASynhvXTygHljmcMbBSDQtLrTZeW+YzIcOgk5UM1yBi26WoUYva2aCr9IRvKdYreAK08OiMdZedpOye0ZdvIYJGcyITwc6YMmrAhP7jZlrk/mDEkf2a4eBp+475o7MJtaC9npqYkToM8vqvx5AGEKqXt7/f1/paOY7KsR+VGPQy6k2RkXjWBsXPesZ3d3XLZHE60wAk0EsuJO8A25+uWSB6ILQeRSYYmGea/WIf6kd [email protected]"
103+
104+
roles:
105+
- ansible-users

0 commit comments

Comments
 (0)