Skip to content

Commit d0f6b37

Browse files
author
Colin Hoglund
authored
Merge pull request #32 from singleplatform-eng/revert-31-master
Revert "Merge SinglePlatform changes"
2 parents fd108f2 + c392aac commit d0f6b37

File tree

12 files changed

+168
-114
lines changed

12 files changed

+168
-114
lines changed

.travis.yml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
1-
---
2-
sudo: required
31
language: python
4-
python: "2.7"
5-
2+
python:
3+
- "2.7"
64
install:
7-
- pip install ansible
8-
9-
# Add ansible.cfg to pick up roles path.
10-
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"
11-
5+
- "pip install ansible"
126
script:
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)
7+
- cd tests
8+
- ansible-playbook --connection=local --limit=localhost --inventory-file=hosts all.yml
259

26-
notifications:
27-
webhooks: https://galaxy.ansible.com/api/v1/notifications/

README.md

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

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

55
Role to manage users on a system.
66

@@ -31,7 +31,6 @@ 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
3534
* ssh-key - This should be a list of ssh keys for the user. Each ssh key
3635
should be included directly and should have no newlines.
3736

@@ -49,14 +48,9 @@ Example:
4948
name: Foo Barrington
5049
groups: ['wheel','systemd-journal']
5150
uid: 1001
52-
profile: |
53-
alias ll='ls -lah'
5451
ssh_key:
5552
- "ssh-rsa AAAAA.... foo@machine"
5653
- "ssh-rsa AAAAB.... foo2@machine"
57-
groups_to_create:
58-
- name: developers
59-
gid: 10000
6054
users_deleted:
6155
- username: bar
6256
name: Bar User

defaults/main.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@ 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
2216
groups_to_create: []

meta/main.yml

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
---
22
galaxy_info:
3-
author: Mark Harrison (Modified by SinglePlatform Engineering)
3+
author: Mark Harrison
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-
galaxy_tags:
35-
- system
36-
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
3736
dependencies: []

tasks/main.yml

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

2726
- name: SSH keys
2827
authorized_key: user="{{item.0.username}}" key="{{item.1}}"
2928
with_subelements:
30-
- "{{users}}"
29+
- users
3130
- ssh_key
3231
tags: ['users','configuration']
3332

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-
4533
- name: Deleted user removal
4634
user: name="{{item.username}}" state=absent
47-
with_items: "{{users_deleted}}"
35+
with_items: users_deleted
4836
tags: ['users','configuration']
4937

5038
- name: Deleted per-user group removal
5139
group: name="{{item.username}}" state=absent
52-
with_items: "{{users_deleted}}"
40+
with_items: users_deleted
5341
when: users_create_per_user_group
5442
tags: ['users','configuration']

tests/add_user.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
3+
# It should add a user when given valid metadata
4+
5+
- hosts: test_runners
6+
sudo: yes
7+
8+
# Test fixture data
9+
vars:
10+
users:
11+
- username: ansibletestuser
12+
name: Ansible Users Role Test Fixture Account
13+
groups:
14+
- 'users'
15+
- 'bin'
16+
uid: 2222
17+
ssh_key:
18+
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVpUJQCOaPg3p5xro9e+1fkGRWNOGrrExiKMqTE91Fwu349bxfMnMzRS0PAERouR9EEL+Ee4Yzhav/uNc35eCtXzACtluXnAncMrQj6pM3IqASynhvXTygHljmcMbBSDQtLrTZeW+YzIcOgk5UM1yBi26WoUYva2aCr9IRvKdYreAK08OiMdZedpOye0ZdvIYJGcyITwc6YMmrAhP7jZlrk/mDEkf2a4eBp+475o7MJtaC9npqYkToM8vqvx5AGEKqXt7/f1/paOY7KsR+VGPQy6k2RkXjWBsXPesZ3d3XLZHE60wAk0EsuJO8A25+uWSB6ILQeRSYYmGea/WIf6kd [email protected]"
19+
20+
# Test setup
21+
pre_tasks:
22+
- include: cleanup.yml
23+
- name: Add Users Test | Pre-Assertions | Ensure ansibletestuser not already present
24+
command: "grep ansibletestuser /etc/passwd /etc/group"
25+
register: ensure_user_not_present
26+
failed_when: ensure_user_not_present.rc == 0
27+
- name: Add Users Test | Pre-Assertions | Ensure ansibletestuser home dir not already present
28+
command: "ls -d /home/ansibletestuser"
29+
register: ensure_home_not_present
30+
failed_when: ensure_home_not_present.rc == 0
31+
32+
# Test run
33+
roles:
34+
- { role: users }
35+
36+
# Test verify successful
37+
tasks:
38+
- name: Add Users Test | Post-Assertions | Ensure ansibletestuser was created
39+
command: "grep ansibletestuser /etc/passwd"
40+
- name: Add Users Test | Post-Assertions | Ensure ansibletestuser home dir was created
41+
command: "ls -d /home/ansibletestuser"
42+
- name: Add Users Test | Post-Assertions | Ensure ssh key was added
43+
command: "sudo grep '{{ users[0].ssh_key[0] }}' /home/ansibletestuser/.ssh/authorized_keys"
44+
- name: Add Users Test | Post-Assertions | Ensure group was added
45+
command: "grep 2222 /etc/group"
46+
- name: Add Users Test | Post-Assertions | Ensure user was added to requested groups
47+
command: "grep '^bin.*ansibletestuser' /etc/group"
48+
49+
# Test tear-down
50+
post_tasks:
51+
- include: cleanup.yml
52+

tests/all.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
# All users role tests
4+
5+
- include: add_user.yml
6+
- include: ssh_keys_optional.yml
7+

tests/cleanup.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
- name: Cleanup | Remove ansibletestuser
4+
user: state="absent" name="ansibletestuser"
5+
6+
- name: Cleanup | Remove ansibletestuser home dir
7+
file: state="absent" path="/home/ansibletestuser"
8+

tests/hosts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[test_runners]
2+
localhost
3+

tests/roles/users

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../

0 commit comments

Comments
 (0)