homeserver/roles/mgrote_users/tasks/main.yml

52 lines
1.5 KiB
YAML
Raw Normal View History

---
- name: Set groups as list
ansible.builtin.set_fact:
2024-10-23 18:01:13 +02:00
groups_as_list: "{{ (((item.groups) | list) | sort) | unique }}"
loop: "{{ users }}"
when: item.groups is defined
become: false
2024-10-08 17:57:13 +02:00
no_log: true
- name: Ensure groups exist
ansible.builtin.group:
name: "{{ item }}"
state: present
loop: '{{ groups_as_list }}'
when: groups_as_list is defined
no_log: true
- name: Ensure users exist
ansible.builtin.user:
name: "{{ item.username }}"
uid: "{{ item.uid | default(omit) }}"
shell: "{{ item.shell | default('/bin/bash') }}"
password: "{{ item.password }}"
update_password: "{{ item.update_password | default(omit) }}"
groups: "{{ item.groups | default(omit) }}"
createhome: "{{ item.createhome | default('yes') }}"
state: "{{ item.state | default('present') }}"
loop: '{{ users }}'
2024-10-23 21:24:24 +02:00
#no_log: true
- name: Ensure user ssh-keys exist
ansible.posix.authorized_key:
user: "{{ item.username }}"
key: "{{ item.public_ssh_key }}"
state: "{{ item.state | default('present') }}"
when: item.public_ssh_key is defined
loop: '{{ users }}'
2024-10-23 21:24:24 +02:00
#no_log: true
- name: Ensure users are added to sudoers
community.general.sudoers:
name: "users-sudo-{{ item.username }}"
state: "{{ item.state | default('present') }}"
2024-10-23 21:47:37 +02:00
user: "(ALL)"
2024-10-23 21:44:44 +02:00
commands: "ALL"
host: "ALL"
nopassword: "{{ item.allow_passwordless_sudo }}"
2024-10-23 21:41:54 +02:00
validation: absent #todo required
loop: '{{ users }}'
when: item.allow_sudo|default(false) and item.allow_sudo is defined
2024-10-23 21:24:24 +02:00
#no_log: true