Skip to content

Commit

Permalink
Merge pull request #6 from soupdiver/issue_3
Browse files Browse the repository at this point in the history
Issue 3
  • Loading branch information
soupdiver committed Feb 21, 2015
2 parents 2c51a6d + 578976a commit 9efc8e4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
install:
- pip install ansible==1.5.0
- pip install ansible>=1.8.0
script:
- echo localhost > inventory
- ansible-playbook --syntax-check -i inventory test.yml
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Ansible role which manages the groups and user accounts.


#### Requirements & Dependencies
- Tested on Ansible 1.4 or higher.
- Tested on Ansible 1.8 or higher.


#### Variables

```yaml
genericusers_groups:
- name: "dbadmins"
gid: 5000
system: no
gid: 5000 # (Optional)
system: no # (Optional)
- name: "mailadmins"
gid: 6000
system: no
Expand All @@ -24,15 +24,15 @@ genericusers_groups_removed:
genericusers_users:
- name: "foo"
groups: ["admin", "staff", "devops"]
ssh_keys:
ssh_keys: # Keys to add to authorized_keys
- "ssh-dss ......."
- "ssh-dss ......."
append: "no" # If yes, will only add groups, not set them to just the list in groups.
pass: "$6$...." # Set the user's password to this crypted value.
comment: "foo acc" #
shell: "/bin/bash" # Set the user's shell.
home: "/home/baz" # Set the user's home directory.
system: no # Make the user a system account or not.
append: "no" # (Optional) If yes, will only add groups, not set them to just the list in groups.
pass: "$6$...." # (Optional) Set the user's password to this crypted value.
comment: "foo acc" # (Optional)
shell: "/bin/bash" # (Optional) Set the user's shell.
home: "/home/baz" # (Optional) Set the user's home directory.
system: no # (Optional) Make the user a system account or not.
- name: "bar"
groups: ["admin", "staff", "dev"]
ssh_keys: []
Expand Down
33 changes: 27 additions & 6 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
# file: generic-users/tasks/main.yml

- name: generic-users | Make sure all groups are present
group: name="{{item.name}}"{% if item.system is defined %} system="{{item.system}}"{% endif %}{% if item.gid is defined %} gid="{{item.gid}}"{% endif %} state=present
group:
name: "{{ item.name }}"
system: "{{ item.system | default(omit) }}"
gid: "{{ item.gid | default(omit) }}"
state: present
with_items: genericusers_groups

- name: generic-users | Make sure all removed groups are not present
group: name="{{item.name}}" state=absent
group:
name: "{{ item.name }}"
state: absent
with_items: genericusers_groups_removed

- name: generic-users | Make sure the users are present
user: name="{{item.name}}" groups="{{','.join(item.groups)}}"{% if item.append is defined %} append="{{item.append}}"{% endif %}{% if item.pass is defined %} password="{{item.pass}}"{% endif %}{% if item.comment is defined %} comment='"{{item.comment}}"'{% endif %}{% if item.shell is defined %} shell="{{item.shell}}"{% endif %}{% if item.uid is defined %} uid="{{item.uid}}"{% endif %}{% if item.home is defined %} home="{{item.home}}"{% endif %}{% if item.system is defined %} system="{{item.system}}"{% endif %} state=present
user:
name: "{{ item.name }}"
groups: "{{ ','.join(item.groups) }}"
append: "{{ item.append | default(omit) }}"
password: "{{ item.pass | default(omit) }}"
comment: "{{ item.comment | default(omit) }}"
shell: "{{ item.shell | default(omit) }}"
uid: "{{ item.uid | default(omit) }}"
home: "{{ item.home | default(omit) }}"
system: "{{ item.system | default(omit) }}"
state: present
with_items: genericusers_users

- name: generic-users | Make sure all removed groups are not present
user: name="{{item.name}}" state=absent remove=yes
- name: generic-users | Make sure all removed users are not present
user:
name: "{{item.name}}"
state: absent
remove: yes
with_items: genericusers_users_removed

- name: generic-users | Install the ssh keys for the users
authorized_key: "user='{{item.0.name}}' key='{{item.1}}'"
authorized_key:
user: "{{item.0.name}}"
key: "{{item.1}}"
with_subelements:
- genericusers_users
- ssh_keys

0 comments on commit 9efc8e4

Please sign in to comment.