Skip to content

Commit ce41d52

Browse files
author
Colin Hoglund
authored
Merge pull request #33 from singleplatform-eng/singleplatform_additions
singleplatform additions
2 parents e6d9964 + a42a648 commit ce41d52

File tree

6 files changed

+114
-51
lines changed

6 files changed

+114
-51
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

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

@@ -50,9 +51,14 @@ Example:
5051
name: Foo Barrington
5152
groups: ['wheel','systemd-journal']
5253
uid: 1001
54+
profile: |
55+
alias ll='ls -lah'
5356
ssh_key:
5457
- "ssh-rsa AAAAA.... foo@machine"
5558
- "ssh-rsa AAAAB.... foo2@machine"
59+
groups_to_create:
60+
- name: developers
61+
gid: 10000
5662
users_deleted:
5763
- username: bar
5864
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
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}}"
99
gid="{{item.gid if item.gid is defined else item.uid}}"
1010
with_items: users
11+
with_items: "{{users}}"
1112
when: users_create_per_user_group
1213
tags: ['users','configuration']
1314

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

2729
- name: SSH keys
2830
authorized_key: user="{{item.0.username}}" key="{{item.1}}"
2931
with_subelements:
30-
- users
32+
- "{{users}}"
3133
- ssh_key
3234
tags: ['users','configuration']
3335

36+
- name: Setup user profiles
37+
blockinfile:
38+
block: "{{item.profile}}"
39+
dest: "/home/{{item.username}}/.profile"
40+
owner: "{{item.username}}"
41+
group: "{{item.username}}"
42+
mode: 0644
43+
create: true
44+
when: users_create_homedirs and item.profile is defined
45+
with_items: "{{users}}"
46+
3447
- name: Deleted user removal
3548
user: name="{{item.username}}" state=absent
36-
with_items: users_deleted
49+
with_items: "{{users_deleted}}"
3750
tags: ['users','configuration']
3851

3952
- name: Deleted per-user group removal
4053
group: name="{{item.username}}" state=absent
41-
with_items: users_deleted
54+
with_items: "{{users_deleted}}"
4255
when: users_create_per_user_group
4356
tags: ['users','configuration']

tests/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
3+
- hosts: localhost
4+
remote_user: root
5+
vars:
6+
users:
7+
- name: Ansible Test User
8+
username: ansibletestuser
9+
uid: 2222
10+
groups: [users, bin]
11+
shell: /bin/sh
12+
profile: |
13+
alias ll='ls -lah'
14+
alias cp='cp -iv'
15+
ssh_key:
16+
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVpUJQCOaPg3p5xro9e+1fkGRWNOGrrExiKMqTE91Fwu349bxfMnMzRS0PAERouR9EEL+Ee4Yzhav/uNc35eCtXzACtluXnAncMrQj6pM3IqASynhvXTygHljmcMbBSDQtLrTZeW+YzIcOgk5UM1yBi26WoUYva2aCr9IRvKdYreAK08OiMdZedpOye0ZdvIYJGcyITwc6YMmrAhP7jZlrk/mDEkf2a4eBp+475o7MJtaC9npqYkToM8vqvx5AGEKqXt7/f1/paOY7KsR+VGPQy6k2RkXjWBsXPesZ3d3XLZHE60wAk0EsuJO8A25+uWSB6ILQeRSYYmGea/WIf6kd [email protected]"
17+
18+
roles:
19+
- ansible-users

0 commit comments

Comments
 (0)