feat(role): init
Some checks failed
checks-test / Lint (push) Failing after 34s
checks-test / molecule (rockylinux9) (push) Failing after 2m53s
checks-test / molecule (ubuntu2204) (push) Failing after 2m45s
checks-test / molecule (debian11) (push) Successful in 3m50s

This commit is contained in:
2024-01-14 19:04:48 +02:00
commit be7b37ee2e
15 changed files with 334 additions and 0 deletions

6
tasks/group.yml Normal file
View File

@@ -0,0 +1,6 @@
---
- name: "Create group `{{ group }}`"
become: true
group:
name: "{{ group }}"
gid: "{{ users_groups[group].get('gid', None) }}"

11
tasks/main.yml Normal file
View File

@@ -0,0 +1,11 @@
---
- include_tasks: group.yml
with_items: "{{ users_groups.keys() }}"
loop_control:
loop_var: group
- include_tasks: user.yml
when: ansible_default_ipv4.address in users[username]['passwords'] or users[username]['passwords'].get('default')
with_items: "{{ users.keys() }}"
loop_control:
loop_var: username

30
tasks/user.yml Normal file
View File

@@ -0,0 +1,30 @@
---
- name: "create user `{{ username }}`"
ansible.builtin.user:
name: "{{ username }}"
append: true
groups: "{{ users[username].get('groups', '') }}"
shell: "{{ users[username].get('shell', '/bin/bash') }}"
uid: "{{ users[username].get('uid', None) }}"
- name: "set specific password for user `{{ username }}`"
ansible.builtin.user:
name: "{{ username }}"
password: "{{ users[username]['passwords'].get(ansible_default_ipv4.address) }}"
when: "ansible_default_ipv4.address in users[username]['passwords'] and
users[username]['passwords'].get(ansible_default_ipv4.address) != 'default'"
- name: "set default password for user `{{ username }}`"
ansible.builtin.user:
name: "{{ username }}"
password: "{{ users[username]['passwords'].get('default') }}"
when: "ansible_default_ipv4.address not in users[username]['passwords'] or
users[username]['passwords'].get(ansible_default_ipv4.address) == 'default'"
- name: "setup ssh key for user `{{ username }}`"
ansible.builtin.authorized_key:
user: "{{ username }}"
state: "{{ users[username]['authorized_keys'][item].get('state', 'present') }}"
key: "{{ users[username]['authorized_keys'][item].get('key') }}"
with_items: "{{ users[username]['authorized_keys'].keys() }}"
when: '"authorized_keys" in users[username]'