fix: loop cosmetics and verbose outputs

This commit is contained in:
jez 2025-07-09 17:37:59 -04:00
parent 75ca524808
commit a5e773a007
4 changed files with 32 additions and 15 deletions

View File

@ -2,9 +2,10 @@
- name: Display nfs_client role
ansible.builtin.debug:
var: base_config
var: role_config
verbosity: 0
vars:
base_config:
role_config:
nfs_mounts: "{{ nfs_mounts }}"
tasks:
- Ensure nfs-client packages are installed

View File

@ -2,9 +2,10 @@
- name: Display os_base role
ansible.builtin.debug:
var: base_config
var: role_config
verbosity: 1
vars:
base_config:
role_config:
system_accounts: "{{ system_accounts }}"
system_packages: "{{ system_packages }}"
tasks:
@ -29,6 +30,8 @@
loop:
- wheel
- sudo
loop_control:
label: "Install package: {{ item }}"
- name: Create users
user:
@ -37,26 +40,33 @@
groups: "{{ item.groups | default([]) }}"
state: "{{ item.state | default('present') }}"
shell: "{{ item.shell | default('/bin/bash') }}"
system: "{{ item.system | default(False) }}"
system: "{{ _system }}"
comment: "{{ item.comment | default(omit) }}"
createhome: true
home: "{{ item.home | default('/home/' + item.name ) }}"
uid: "{{ item.uid | default(omit) }}"
loop: "{{ system_accounts }}"
loop_control:
label: "Create {{ _system | ternary('system', 'regular') }} user: {{ item.name }} ({{ item.uid }}, {{item.comment|d('No comments')}}"
vars:
_system: "{{ item.system | default(False) }}"
- name: Deploy all ssh keys
ansible.posix.authorized_key:
user: "{{ user_name }}"
state: "{{ sshkey_state }}"
key: "{{ sshkey }}"
user: "{{ _user_name }}"
state: "{{ _sshkey_state }}"
key: "{{ _sshkey }}"
follow: true
path: "{{ home_dir }}/.ssh/authorized_keys"
path: "{{ _home_dir }}/.ssh/authorized_keys"
loop: "{{ system_accounts|selectattr('sshkeys', 'defined') | subelements('sshkeys') }}"
loop_control:
label: "Deploy '{{ _user_name }}' public key: {{ _sshkey_comment }}"
vars:
user_name: "{{ item.0.name }}"
home_dir: "{{ item.0.home | default('/home/' + item.0.name ) }}"
sshkey_state: "{{ item.0.sshkey_state | default('present') }}"
sshkey: "{{ item.1 }}"
_user_name: "{{ item.0.name }}"
_home_dir: "{{ item.0.home | default('/home/' + item.0.name ) }}"
_sshkey_state: "{{ item.0.sshkey_state | default('present') }}"
_sshkey: "{{ item.1 }}"
_sshkey_comment: "{{ _sshkey | split(' ') | last }}"
# Configure package manager
@ -73,6 +83,8 @@
- name: 02-suggest
content: |
APT::Install-Suggests "{{ system_packages_nosuggest | bool | ternary(0, 1) }}";
loop_control:
label: "Ensure APT preference: {{ item.content }}"
- name: Install base tools
package:
@ -98,6 +110,8 @@
groups:
- sudo
with_items: "{{ system_accounts }}"
loop_control:
label: "Add user to sudo group: {{ item.name }}"
when: "'sudo' in perm"
vars:
perm: "{{ item.permissions | default([]) }}"

View File

@ -2,9 +2,10 @@
- name: Display os_disks role
ansible.builtin.debug:
var: disk_config
var: role_config
verbosity: 0
vars:
disk_config:
role_config:
disks_vg: "{{ disks_vg }}"
disks_lv: "{{ disks_lv }}"
tasks:

View File

@ -3,6 +3,7 @@
- name: Display os_systemd_networkd role
ansible.builtin.debug:
var: role_config
verbosity: 1
vars:
role_config:
systemd_networkd_conf_directory: "{{ systemd_networkd_conf_directory }}"