Fix pi_standard_setup under --check

Skipped command tasks return stdout: "" rather than being undefined, so
"src: motd/{{ ...stdout }}" collapsed to "motd/" - a directory - and copy
switched to recursive mode, failing with "/etc/motd/<file>: Not a
directory". The empty boot-target stdout likewise never equals
"multi-user.target", so "Set boot mode to CLI" always reported changed.

Run the three read-only commands in check mode. They are all
changed_when: false already, so this is safe.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-19 16:22:50 +02:00
parent 85a26db46b
commit 07e3c2797e

View File

@@ -36,6 +36,7 @@
ansible.builtin.command: "raspi-config nonint get_hostname"
register: pi_standard_setup_pi_hostname
changed_when: false
check_mode: false # read-only; must run in --check so .stdout isn't empty
- name: Change hostname {{ pi_standard_setup_new_hostname }}
ansible.builtin.command: "raspi-config nonint do_hostname {{ pi_standard_setup_new_hostname }}"
when: pi_standard_setup_new_hostname | length > 0 and pi_standard_setup_pi_hostname.stdout != pi_standard_setup_new_hostname
@@ -46,10 +47,12 @@
ansible.builtin.command: "raspi-config nonint get_hostname"
register: pi_standard_setup_pi_hostname
changed_when: false
check_mode: false # read-only; must run in --check so .stdout isn't empty
- name: Get current boot target
ansible.builtin.command: "systemctl get-default"
register: pi_standard_setup_boot_target
changed_when: false
check_mode: false # read-only; must run in --check so .stdout isn't empty
- name: Set boot mode to CLI
ansible.builtin.command: "raspi-config nonint do_boot_behaviour B1"
when: pi_standard_setup_boot_target.stdout != "multi-user.target"