Merge pull request #7 from n0emis/e1mo/groups

Add support for custom user groups
main
n0emis 4 years ago committed by GitHub
commit 2c71b5b035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,6 @@
--- ---
user_groups: []
users: users:
- { name: 'user', state: 'present', public_key: '' } - { name: 'user', state: 'present', public_key: '' }
- { name: 'nouser', state: 'absent', public_key: '' } - { name: 'nouser', state: 'absent', public_key: '' }

@ -7,6 +7,12 @@
with_items: with_items:
- "{{ users }}" - "{{ users }}"
- name: Ensure all groups are present or absent
group:
name: '{{ item.name | default(item) }}'
state: '{{ item.state | default("present") }}'
with_items: '{{ user_groups }}'
- name: get bash's path - name: get bash's path
command: which bash command: which bash
register: bash_path register: bash_path
@ -14,10 +20,15 @@
changed_when: false changed_when: false
- name: create user - name: create user
user: state=present user:
name="{{ item.username if item.username is defined else item.name }}" state: present
groups="{{ "sudo,adm" if item.sudo is defined and item.sudo }}" append=yes name: "{{ item.username if item.username is defined else item.name }}"
shell={{ item.shell | default(bash_path.stdout) }} groups:
- "{{ item.groups | default([]) | join(',')}}"
- "{{ 'sudo,adm' if item.sudo is defined and item.sudo }}"
append: true
shell: '{{ item.shell | default(bash_path.stdout) }}'
home: "{{ item.home | default('/home/' + (item.username | default(item.name))) }}"
with_items: with_items:
- "{{ users }}" - "{{ users }}"
when: item.state != 'absent' when: item.state != 'absent'

Loading…
Cancel
Save