fix(cloud-init): handle missing keys and make sudo conditional
This commit is contained in:
@@ -8,13 +8,14 @@ users:
|
|||||||
- name: "{{ user.name }}"
|
- name: "{{ user.name }}"
|
||||||
primary_group: "{{ user.name }}"
|
primary_group: "{{ user.name }}"
|
||||||
groups: users
|
groups: users
|
||||||
|
{% if user.sudo | default(false) | bool %}
|
||||||
sudo: "ALL=(ALL) NOPASSWD:ALL"
|
sudo: "ALL=(ALL) NOPASSWD:ALL"
|
||||||
|
{% endif %}
|
||||||
passwd: "{{ user.password | password_hash('sha512') }}"
|
passwd: "{{ user.password | password_hash('sha512') }}"
|
||||||
lock_passwd: false
|
lock_passwd: false
|
||||||
{% set ssh_keys = user['keys'] | default([]) %}
|
{% if 'keys' in user and user['keys'] is iterable and user['keys'] is not string and user['keys'] | length > 0 %}
|
||||||
{% if ssh_keys | length > 0 %}
|
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
{% for key in ssh_keys %}
|
{% for key in user['keys'] %}
|
||||||
- "{{ key }}"
|
- "{{ key }}"
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user