I want to create a handler to reboot a device only when changes are detected. It doesn’t need to be a handler if its not best practice, but I want to have something to reboot that device automatically. With the .yaml below, every time on run this it reboots all the devices I have listed in my inventory [raspi5].
---
- name: Touch each Raspberry Pi5 and Do Maintenance
hosts: [raspi5]
gather_facts: true
become: true
tasks:
- name: Upgrade the RaspiOS (apt-get dist-upgrade)
ansible.builtin.apt:
upgrade: dist
- name: Run the equivalent of "apt-get update" as a separate step
ansible.builtin.apt:
update_cache: yes
- name: Update all packages to their latest version
ansible.builtin.apt:
name: "*"
state: latest
- name: Install Neofetch
ansible.builtin.apt:
name: neofetch
state: latest
- name: Install XRDP
ansible.builtin.apt:
name: xrdp
state: latest
- name: Create a directory if it does not exist
ansible.builtin.file:
path: /Desktop/output/
state: directory
mode: '0755'
- name: Unconditionally reboot the machine with all defaults
ansible.builtin.reboot:
4