diff --git a/roles/pi_standard_setup/tasks/main.yml b/roles/pi_standard_setup/tasks/main.yml index 8b6b6e4..d9f29de 100644 --- a/roles/pi_standard_setup/tasks/main.yml +++ b/roles/pi_standard_setup/tasks/main.yml @@ -48,6 +48,14 @@ register: pi_standard_setup_pi_hostname changed_when: false check_mode: false # read-only; must run in --check so .stdout isn't empty +# raspi-config's do_hostname only rewrites the 127.0.1.1 line if it already +# contains the *old* hostname. Ours said "raspberrypi", so every rename since +# the first one has silently left this stale. +- name: Point 127.0.1.1 at the current hostname + ansible.builtin.lineinfile: + path: /etc/hosts + regexp: '^127\.0\.1\.1\s' + line: "127.0.1.1\t{{ pi_standard_setup_pi_hostname.stdout }}" - name: Get current boot target ansible.builtin.command: "systemctl get-default" register: pi_standard_setup_boot_target