Infra: AWS Update to Ubuntu 20.04
[csit.git] / fdio.infra.ansible / roles / user_add / tasks / main.yaml
1 ---
2 # file: roles/user_add/tasks/main.yaml
3
4 - name: Conf - Add User
5   user:
6     append: "{{ item.append | default(omit) }}"
7     createhome: "{{ 'yes' if users_create_homedirs else 'no' }}"
8     generate_ssh_key: "{{ item.generate_ssh_key | default(omit) }}"
9     groups: "{{ item.groups | join(',') if 'groups' in item else '' }}"
10     name: "{{ item.username }}"
11     password: "{{ item.password if item.password is defined else '!' }}"
12     shell: "{{ item.shell if item.shell is defined else users_shell }}"
13     state: present
14   with_items: "{{ users }}"
15   tags:
16     - user-add-conf
17
18 - name: Conf - SSH keys
19   authorized_key:
20     user: "{{ item.0.username }}"
21     key: "{{ item.1 }}"
22   with_subelements:
23     - "{{ users }}"
24     - ssh_key
25     - skip_missing: yes
26   tags:
27     - user-add-conf
28
29 - name: Conf - Allow Password Login
30   lineinfile:
31     dest: "/etc/ssh/sshd_config"
32     regexp: "^PasswordAuthentication no"
33     line: "PasswordAuthentication yes"
34   notify:
35     - "Restart SSHd"
36   tags:
37     - user-add-conf
38
39 - name: Conf - Add Visudo Entry
40   lineinfile:
41     dest: "/etc/sudoers"
42     state: present
43     line: "{{ item.username }} ALL=(ALL) NOPASSWD: ALL"
44     validate: "visudo -cf %s"
45   with_items: "{{ users }}"
46   tags:
47     - user-add-conf
48