refactor(global_defaults): derive the primary user once for every consumer
This commit is contained in:
@@ -217,7 +217,7 @@ When `interfaces` is empty, the flat fields (`bridge`, `ip`, `prefix`, `gateway`
|
|||||||
|
|
||||||
#### `system.users`
|
#### `system.users`
|
||||||
|
|
||||||
Dict keyed by username. At least one user must have a `password` (used for SSH access during bootstrap). Users without a password get locked accounts (key-only auth).
|
Dict keyed by username. At least one user must have a non-empty `password`: the first such user, in declaration order, is the account bootstrap logs in as after the reboot and the cloud-init and Proxmox `ciuser` primary user. Users without a password get locked accounts (key-only auth).
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
system:
|
system:
|
||||||
|
|||||||
@@ -119,15 +119,13 @@
|
|||||||
when:
|
when:
|
||||||
- post_reboot_can_connect | bool
|
- post_reboot_can_connect | bool
|
||||||
no_log: true
|
no_log: true
|
||||||
vars:
|
|
||||||
_primary: "{{ (system_cfg.users | dict2items | selectattr('value.password', 'defined') | first) }}"
|
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
ansible_connection: ssh
|
ansible_connection: ssh
|
||||||
ansible_host: "{{ system_cfg.network.ip }}"
|
ansible_host: "{{ system_cfg.network.ip }}"
|
||||||
ansible_port: 22
|
ansible_port: 22
|
||||||
ansible_user: "{{ _primary.key }}"
|
ansible_user: "{{ bootstrap_primary_user.name }}"
|
||||||
ansible_password: "{{ _primary.value.password }}"
|
ansible_password: "{{ bootstrap_primary_user.password }}"
|
||||||
ansible_become_password: "{{ _primary.value.password }}"
|
ansible_become_password: "{{ bootstrap_primary_user.password }}"
|
||||||
ansible_ssh_extra_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
ansible_ssh_extra_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,17 @@
|
|||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
system_cfg: "{{ system_cfg | combine({'path': hypervisor_cfg.folder | string}, recursive=True) }}"
|
system_cfg: "{{ system_cfg | combine({'path': hypervisor_cfg.folder | string}, recursive=True) }}"
|
||||||
|
|
||||||
|
# Guarded so a malformed users input reaches the validation message, not a filter error.
|
||||||
|
- name: Pick the primary user (first with a password)
|
||||||
|
vars:
|
||||||
|
_first: >-
|
||||||
|
{{ (system_cfg.users if system_cfg.users is mapping else {}) | dict2items
|
||||||
|
| selectattr('value', 'mapping') | selectattr('value.password', 'defined')
|
||||||
|
| rejectattr('value.password', 'equalto', '') | first | default({}) }}
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
bootstrap_primary_user: "{{ {'name': _first.key, 'password': _first.value.password} if _first else {} }}"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: Validate variables
|
- name: Validate variables
|
||||||
ansible.builtin.include_tasks: validation.yml
|
ansible.builtin.include_tasks: validation.yml
|
||||||
|
|
||||||
@@ -89,14 +100,12 @@
|
|||||||
when:
|
when:
|
||||||
- system_cfg.type == "virtual"
|
- system_cfg.type == "virtual"
|
||||||
- hypervisor_type != "vmware"
|
- hypervisor_type != "vmware"
|
||||||
vars:
|
|
||||||
_primary: "{{ (system_cfg.users | dict2items | selectattr('value.password', 'defined') | first) }}"
|
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
ansible_host: "{{ system_cfg.network.ip }}"
|
ansible_host: "{{ system_cfg.network.ip }}"
|
||||||
ansible_port: 22
|
ansible_port: 22
|
||||||
ansible_user: "{{ _primary.key }}"
|
ansible_user: "{{ bootstrap_primary_user.name }}"
|
||||||
ansible_password: "{{ _primary.value.password }}"
|
ansible_password: "{{ bootstrap_primary_user.password }}"
|
||||||
ansible_become_password: "{{ _primary.value.password }}"
|
ansible_become_password: "{{ bootstrap_primary_user.password }}"
|
||||||
ansible_ssh_extra_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
ansible_ssh_extra_args: "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{{ out }}
|
{{ out }}
|
||||||
community.proxmox.proxmox_kvm:
|
community.proxmox.proxmox_kvm:
|
||||||
ciuser: "{{ (system_cfg.users | dict2items | selectattr('value.password', 'defined') | first).key }}"
|
ciuser: "{{ bootstrap_primary_user.name }}"
|
||||||
cipassword: "{{ (system_cfg.users | dict2items | selectattr('value.password', 'defined') | first).value.password }}"
|
cipassword: "{{ bootstrap_primary_user.password }}"
|
||||||
ciupgrade: false
|
ciupgrade: false
|
||||||
vmid: "{{ system_cfg.id }}"
|
vmid: "{{ system_cfg.id }}"
|
||||||
name: "{{ hostname }}"
|
name: "{{ hostname }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user