Skip to content

Commit fd108f2

Browse files
author
Colin Hoglund
authored
Merge pull request #31 from singleplatform-eng/master
Merge SinglePlatform changes
2 parents db443a2 + df4d702 commit fd108f2

File tree

12 files changed

+114
-168
lines changed

12 files changed

+114
-168
lines changed

.travis.yml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
---
2+
sudo: required
13
language: python
2-
python:
3-
- "2.7"
4+
python: "2.7"
5+
46
install:
5-
- "pip install ansible"
7+
- pip install ansible
8+
9+
# Add ansible.cfg to pick up roles path.
10+
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
11+
612
script:
7-
- cd tests
8-
- ansible-playbook --connection=local --limit=localhost --inventory-file=hosts all.yml
13+
# Syntax Check
14+
- ansible-playbook -i localhost, tests/test.yml --syntax-check
15+
16+
# Run test.yml
17+
- ansible-playbook -i localhost, --connection=local --sudo tests/test.yml
18+
19+
# Run the role/playbook again, checking to make sure it's idempotent.
20+
- >
21+
ansible-playbook -i localhost, --connection=local --sudo tests/test.yml
22+
| grep -q 'changed=0.*failed=0'
23+
&& (echo 'Idempotence test: pass' && exit 0)
24+
|| (echo 'Idempotence test: fail' && exit 1)
925
26+
notifications:
27+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[![Build Status](https://travis-ci.org/mivok/ansible-users.png)](https://travis-ci.org/mivok/ansible-users)
1+
[![Build Status](https://travis-ci.org/singleplatform-eng/ansible-users.svg?branch=master)](https://travis-ci.org/singleplatform-eng/ansible-users)
22

3-
# Users role
3+
# ansible-users
44

55
Role to manage users on a system.
66

@@ -31,6 +31,7 @@ The following attributes are required for each user:
3131
* password - If a hash is provided then that will be used, but otherwise the
3232
account will be locked
3333
* groups - a list of supplementary groups for the user.
34+
* profile - a string block for setting custom shell profiles
3435
* ssh-key - This should be a list of ssh keys for the user. Each ssh key
3536
should be included directly and should have no newlines.
3637

@@ -48,9 +49,14 @@ Example:
4849
name: Foo Barrington
4950
groups: ['wheel','systemd-journal']
5051
uid: 1001
52+
profile: |
53+
alias ll='ls -lah'
5154
ssh_key:
5255
- "ssh-rsa AAAAA.... foo@machine"
5356
- "ssh-rsa AAAAB.... foo2@machine"
57+
groups_to_create:
58+
- name: developers
59+
gid: 10000
5460
users_deleted:
5561
- username: bar
5662
name: Bar User

defaults/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ users_create_homedirs: true
1313
# Lists of users to create and delete
1414
users: []
1515
users_deleted: []
16+
17+
# List of groups to create
18+
# Example:
19+
# groups_to_create:
20+
# - name: developers
21+
# gid: 10000
1622
groups_to_create: []

meta/main.yml

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
---
22
galaxy_info:
3-
author: Mark Harrison
3+
author: Mark Harrison (Modified by SinglePlatform Engineering)
44
description: User creation role
55
license: MIT
66
min_ansible_version: 1.3
77
platforms:
8-
- name: EL
9-
versions:
10-
- all
11-
- name: GenericUNIX
12-
versions:
13-
- all
14-
- any
15-
- name: Fedora
16-
versions:
17-
- all
18-
- name: opensuse
19-
versions:
20-
- all
21-
- name: Ubuntu
22-
versions:
23-
- all
24-
- name: SLES
25-
versions:
26-
- all
27-
- name: GenericLinux
28-
versions:
29-
- all
30-
- any
31-
- name: Debian
32-
versions:
33-
- all
34-
categories:
35-
- system
8+
- name: EL
9+
versions:
10+
- all
11+
- name: GenericUNIX
12+
versions:
13+
- all
14+
- any
15+
- name: Fedora
16+
versions:
17+
- all
18+
- name: opensuse
19+
versions:
20+
- all
21+
- name: Ubuntu
22+
versions:
23+
- all
24+
- name: SLES
25+
versions:
26+
- all
27+
- name: GenericLinux
28+
versions:
29+
- all
30+
- any
31+
- name: Debian
32+
versions:
33+
- all
34+
galaxy_tags:
35+
- system
36+
3637
dependencies: []

tasks/main.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,54 @@
11
---
22
- name: Creating groups
3-
group: name="{{item}}"
4-
with_items: groups_to_create
3+
group: name="{{item.name}}" gid="{{item.gid | default(omit)}}"
4+
with_items: "{{groups_to_create}}"
55
tags: ['users','groups','configuration']
66

77
- name: Per-user group creation
88
group: name="{{item.username}}" gid="{{item.uid}}"
9-
with_items: users
9+
with_items: "{{users}}"
1010
when: users_create_per_user_group
1111
tags: ['users','configuration']
1212

1313
- name: User creation
14-
user: name="{{item.username}}"
15-
group="{{item.username if users_create_per_user_group
16-
else users_group}}"
17-
groups="{{item.groups | join(',')}}"
18-
shell={{item.shell if item.shell is defined else users_default_shell}}
19-
password="{{item.password if item.password is defined else '!'}}"
20-
comment="{{item.name}}"
21-
uid="{{item.uid}}"
22-
createhome="{{'yes' if users_create_homedirs else 'no'}}"
23-
with_items: users
14+
user:
15+
name: "{{item.username}}"
16+
group: "{{item.username if users_create_per_user_group else users_group}}"
17+
# empty string removes user from all secondary groups
18+
groups: "{{item.groups | join(',') if 'groups' in item else ''}}"
19+
shell: "{{item.shell if item.shell is defined else users_default_shell}}"
20+
password: "{{item.password if item.password is defined else '!'}}"
21+
comment: "{{item.name}}"
22+
uid: "{{item.uid}}"
23+
createhome: "{{'yes' if users_create_homedirs else 'no'}}"
24+
with_items: "{{users}}"
2425
tags: ['users','configuration']
2526

2627
- name: SSH keys
2728
authorized_key: user="{{item.0.username}}" key="{{item.1}}"
2829
with_subelements:
29-
- users
30+
- "{{users}}"
3031
- ssh_key
3132
tags: ['users','configuration']
3233

34+
- name: Setup user profiles
35+
blockinfile:
36+
block: "{{item.profile}}"
37+
dest: "/home/{{item.username}}/.profile"
38+
owner: "{{item.username}}"
39+
group: "{{item.username}}"
40+
mode: 0644
41+
create: true
42+
when: users_create_homedirs and item.profile is defined
43+
with_items: "{{users}}"
44+
3345
- name: Deleted user removal
3446
user: name="{{item.username}}" state=absent
35-
with_items: users_deleted
47+
with_items: "{{users_deleted}}"
3648
tags: ['users','configuration']
3749

3850
- name: Deleted per-user group removal
3951
group: name="{{item.username}}" state=absent
40-
with_items: users_deleted
52+
with_items: "{{users_deleted}}"
4153
when: users_create_per_user_group
4254
tags: ['users','configuration']

tests/add_user.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/all.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/cleanup.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/hosts

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/roles/users

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)