diff --git a/.travis.yml b/.travis.yml index 9b90639..80cd4bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 937fce1..fa6e31e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 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 @@ -12,8 +12,8 @@ Ansible role which manages the groups and user accounts. ```yaml genericusers_groups: - name: "dbadmins" - gid: 5000 - system: no + gid: 5000 # (Optional) + system: no # (Optional) - name: "mailadmins" gid: 6000 system: no @@ -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: [] diff --git a/tasks/main.yml b/tasks/main.yml index 26dddda..295a42d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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