Files
ansible/roles/pi_dhtsensor/tasks/main.yml
Martin Bauer 3d1675528b Fix tasks that always report changed regardless of actual state
Several roles reported "changed" on every playbook run even when
nothing on the target had drifted, making real config drift
indistinguishable from noise:

- 7 systemd tasks across 6 roles used state:restarted, which always
  issues a restart and always reports changed. Switched to
  state:started plus notify-driven handlers that only restart when
  the underlying unit file, script, or config actually changes.
- pi_standard_setup's boot mode, timezone, and locale tasks shelled
  out to raspi-config with changed_when:true hardcoded. Boot mode now
  checks systemctl get-default first; timezone/locale now use the
  natively idempotent community.general.timezone/locale_gen modules.
- The pi account password task computed password_hash('sha512')
  without a seed, generating a new random salt (and thus an
  apparently different hash) on every run. Added a stable seed so the
  hash only changes when the underlying secret does.

Also renamed a mislabeled task in pi_squeezelite_custom and fixed a
typo in pi_standard_setup while those files were already touched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-08 21:28:36 +02:00

53 lines
1.5 KiB
YAML

---
# Use the deprecated version here instead, not the new circuitpython adafruit-circuitpython-dht version
# the new version needs a lot of CPU time and doesn't work correctly on old raspi 1
# a copy of the deprecated repo is downloaded as zip (if it goes away)
- name: Uninstall libgpiod2 (circuitpython) if present
ansible.builtin.apt:
name: libgpiod2
cache_valid_time: "7200"
state: absent
- name: Pip uninstall adafruit-circuitpython-dht
ansible.builtin.pip:
name: adafruit-circuitpython-dht
executable: pip3
state: absent
extra_args: "--break-system-packages"
- name: Pip install adafruit-dht
ansible.builtin.pip:
name: adafruit-dht
executable: pip3
extra_args: "--break-system-packages"
notify: Restart dht22_sensing
- name: Install script config
ansible.builtin.template:
src: dht22_sensing.json
dest: /etc/dht22_sensing.json
mode: "0644"
notify: Restart dht22_sensing
- name: Install script
ansible.builtin.copy:
src: dht22_sensing.py
dest: /usr/bin/dht22_sensing
owner: root
mode: u+rwx
notify: Restart dht22_sensing
- name: Install systemd service file
ansible.builtin.copy:
src: dht22_sensing.service
dest: /etc/systemd/system/
mode: "0644"
notify: Restart dht22_sensing
- name: Add script to autostart and start now
ansible.builtin.systemd:
name: dht22_sensing
state: started
enabled: "yes"
daemon_reload: "yes"
- name: Add to sysdweb
ansible.builtin.include_role:
name: pi_sysdweb
vars:
pi_sysdweb_name: dht22_sensing