Skip to content

Commit b10a464

Browse files
author
Colin Hoglund
authored
Merge pull request #39 from zz9pzza/issue_38
Error when users_create_per_user_group is false
2 parents 06a32a5 + 7857279 commit b10a464

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,22 @@ script:
2323
&& (echo 'Idempotence test: pass' && exit 0)
2424
|| (echo 'Idempotence test: fail' && exit 1)
2525
26+
# Lets check on the state of the users. I would invoke severspec myself however
27+
# its a big thing to bring in on a small pull.
28+
- id ansibletestuser | grep --silent "uid=2222(ansibletestuser) gid=2222(ansibletestuser) groups=2222(ansibletestuser),2(bin),100(users)"
29+
- 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)"
31+
- id ansibletestuser4 | grep --silent "uid=2225(ansibletestuser4) gid=100(users) groups=100(users),2(bin)"
32+
- grep --silent "^ansibletestgroup:" /etc/group
33+
- grep --silent "^ansibletestgroup1:" /etc/group
34+
- ls -lgd /home/ansibletestuser | awk '{exit $3!="ansibletestuser"}'
35+
- ls -lgd /home/otherdirectory | awk '{exit $3!="ansibletestuser2"}'
36+
- ls -lgd /home/ansibletestuser3 | awk '{exit $3!="ansibletestgroup"}'
37+
- 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"}'
42+
2643
notifications:
2744
webhooks: https://galaxy.ansible.com/api/v1/notifications/

tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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}}"
44+
group: "{{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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
- hosts: localhost
44
remote_user: root
55
vars:
6+
groups_to_create:
7+
- name: ansibletestgroup
8+
gid: 4000
69
users:
710
- name: Ansible Test User
811
username: ansibletestuser
@@ -36,3 +39,48 @@
3639

3740
roles:
3841
- ansible-users
42+
43+
- hosts: localhost
44+
remote_user: root
45+
vars:
46+
users_create_per_user_group: false
47+
users_group: ansibletestgroup
48+
groups_to_create:
49+
- name: ansibletestgroup1
50+
gid: 4001
51+
users:
52+
- name: Ansible Test User3
53+
username: ansibletestuser3
54+
uid: 2224
55+
group: ansibletestgroup1
56+
groups: [users, bin]
57+
shell: /bin/sh
58+
profile: |
59+
alias ll='ls -lah'
60+
alias cp='cp -iv'
61+
ssh_key:
62+
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVpUJQCOaPg3p5xro9e+1fkGRWNOGrrExiKMqTE91Fwu349bxfMnMzRS0PAERouR9EEL+Ee4Yzhav/uNc35eCtXzACtluXnAncMrQj6pM3IqASynhvXTygHljmcMbBSDQtLrTZeW+YzIcOgk5UM1yBi26WoUYva2aCr9IRvKdYreAK08OiMdZedpOye0ZdvIYJGcyITwc6YMmrAhP7jZlrk/mDEkf2a4eBp+475o7MJtaC9npqYkToM8vqvx5AGEKqXt7/f1/paOY7KsR+VGPQy6k2RkXjWBsXPesZ3d3XLZHE60wAk0EsuJO8A25+uWSB6ILQeRSYYmGea/WIf6kd [email protected]"
63+
64+
roles:
65+
- ansible-users
66+
67+
- hosts: localhost
68+
remote_user: root
69+
vars:
70+
users_create_per_user_group: false
71+
users_group: users
72+
users:
73+
- name: Ansible Test User4
74+
username: ansibletestuser4
75+
uid: 2225
76+
groups: [users, bin]
77+
shell: /bin/sh
78+
home: /home/otherdirectory1
79+
profile: |
80+
alias ll='ls -lah'
81+
alias cp='cp -iv'
82+
ssh_key:
83+
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVpUJQCOaPg3p5xro9e+1fkGRWNOGrrExiKMqTE91Fwu349bxfMnMzRS0PAERouR9EEL+Ee4Yzhav/uNc35eCtXzACtluXnAncMrQj6pM3IqASynhvXTygHljmcMbBSDQtLrTZeW+YzIcOgk5UM1yBi26WoUYva2aCr9IRvKdYreAK08OiMdZedpOye0ZdvIYJGcyITwc6YMmrAhP7jZlrk/mDEkf2a4eBp+475o7MJtaC9npqYkToM8vqvx5AGEKqXt7/f1/paOY7KsR+VGPQy6k2RkXjWBsXPesZ3d3XLZHE60wAk0EsuJO8A25+uWSB6ILQeRSYYmGea/WIf6kd [email protected]"
84+
85+
roles:
86+
- ansible-users

0 commit comments

Comments
 (0)