aboutsummaryrefslogtreecommitdiff
path: root/os_config/roles/users/tasks/main.yml
blob: 990a041378c2a2249e8fd23457673c786bc48e3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
- name: Add users in the system
  user:
    name: "{{ item.username }}"
    #groups: docker
    shell: "{{ item.shell | default('/bin/bash') }}"
    append: no
  loop: "{{ active_users
    | selectattr('is_admin', 'defined') 
    | rejectattr('is_admin')
    | list
    | union( active_users
    | selectattr('is_admin', 'undefined') 
    | list )}}"

- name: Set admin rights
  user:
    name: "{{ item.username }}"
    groups: docker, sudo
    shell: "{{ item.shell | default('/bin/bash') }}"
    append: no
  loop: "{{ active_users
    | selectattr('is_admin', 'defined') 
    | selectattr('is_admin') 
    | list }}"

# [V How SSH Key works] magic is done by subelements, understand the trick at:
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#subelements-filter
- name: Add SSH keys
  authorized_key:
    user: "{{ item.0.username }}"
    state: present
    key: "{{ lookup('file', item.1) }}"
  loop: "{{ active_users | subelements('ssh_keys', skip_missing=True) }}"

- name: Disable old users
  user:
    name: "{{ item }}"
    state: absent
  loop: "{{ disabled_users }}"