fix(users): update cloud-init template and input validation for dict users

This commit is contained in:
MORAWSKI Norbert
2026-03-20 15:10:31 +01:00
parent 3e85a44d8e
commit 704ff21f0e
2 changed files with 13 additions and 9 deletions

View File

@@ -4,18 +4,22 @@ ssh_pwauth: true
package_update: false
package_upgrade: false
users:
{% for user in system_cfg.users %}
- name: "{{ user.name }}"
primary_group: "{{ user.name }}"
{% for username, attrs in system_cfg.users.items() %}
- name: "{{ username }}"
primary_group: "{{ username }}"
groups: users
{% if user.sudo | default(false) | bool %}
{% if attrs.sudo | default(false) | bool %}
sudo: "ALL=(ALL) NOPASSWD:ALL"
{% endif %}
passwd: "{{ user.password | password_hash('sha512') }}"
{% if attrs.password | default('') | length > 0 %}
passwd: "{{ attrs.password | password_hash('sha512') }}"
lock_passwd: false
{% if 'keys' in user and user['keys'] is iterable and user['keys'] is not string and user['keys'] | length > 0 %}
{% else %}
lock_passwd: true
{% endif %}
{% if 'keys' in attrs and attrs['keys'] is iterable and attrs['keys'] is not string and attrs['keys'] | length > 0 %}
ssh_authorized_keys:
{% for key in user['keys'] %}
{% for key in attrs['keys'] %}
- "{{ key }}"
{% endfor %}
{% endif %}