Files
ansible-role-users/tasks/user.yml
Mykhailo Nikiforov f12fe903de
All checks were successful
checks-test / Lint (push) Successful in 16s
checks-test / molecule (debian11) (push) Successful in 2m11s
checks-test / molecule (debian13) (push) Successful in 2m21s
checks-test / molecule (rockylinux10) (push) Successful in 2m19s
checks-test / molecule (debian12) (push) Successful in 2m43s
checks-test / molecule (rockylinux9) (push) Successful in 1m55s
checks-test / molecule (ubuntu2204) (push) Successful in 1m47s
checks-test / molecule (ubuntu2404) (push) Successful in 1m54s
feat: make fixes to be compatible with latest version (#5)
Reviewed-on: #5
Co-authored-by: Mykhailo Nikiforov <mn@palkoi.net>
Co-committed-by: Mykhailo Nikiforov <mn@palkoi.net>
2025-12-06 21:34:55 +02:00

31 lines
1.4 KiB
YAML

---
- 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') if 'uid' in users[username] else omit }}"
- name: "Set specific password for user `{{ username }}`"
ansible.builtin.user:
name: "{{ username }}"
password: "{{ users[username]['passwords'].get(ansible_default_ipv4.address) }}"
when: "ansible_facts['default_ipv4'].address in users[username]['passwords'] and
users[username]['passwords'].get(ansible_facts['default_ipv4'].address) != 'default'"
- name: "Set default password for user `{{ username }}`"
ansible.builtin.user:
name: "{{ username }}"
password: "{{ users[username]['passwords'].get('default') }}"
when: "ansible_facts['default_ipv4'].address not in users[username]['passwords'] or
users[username]['passwords'].get(ansible_facts['default_ipv4'].address) == 'default'"
- name: "Setup ssh key for user `{{ username }}`"
ansible.posix.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]'