system/roles/user/tasks/main.yaml
Marty Oehme 5dd160727a
fix(roles): Default to root as user name
Always default to 'root' as a user_name if no variable has been set.
This can easily happen as not every role sets the variable and instead
we only set it once in the user role. 

Another way to possibly go about it in the future would be to inject the
'user_name' into each role that needs it as one of that role's default
variables. If it is specified by the user somewhere it _should_
override those defaults, though I have to read up on the exact variable
precedence.
2025-03-16 17:44:19 +01:00

27 lines
722 B
YAML

- name: Enable sudo access for "wheel" group
ansible.builtin.copy:
content: "%wheel ALL=(ALL) ALL"
dest: "/etc/sudoers.d/10-wheel"
owner: root
group: root
mode: 0644
force: true
tags: sudo
- name: Ensure all desired user groups exist
ansible.builtin.group:
name: "{{ item }}"
state: "present"
loop: "{{ user_groups }}"
- name: Add primary user
ansible.builtin.user:
name: "{{ user_name | default('root') }}"
password: "{{ user_pass | password_hash('sha512', '{{ user_pass_salt}}') }}"
create_home: true
shell: "/bin/{{ user_shell }}"
group: "{{ user_name | default('root') }}"
groups: "{{ user_groups }}"
generate_ssh_key: true
tags:
- passlib