Ansible code to update all Raspberry Pi
The following code will one by one update your raspberry Pis and then reboot them.
---
- hosts: all
remote_user: pi
serial: 1
tasks:
– name: Update all packages
apt:
upgrade: dist
update_cache: yes
become: yes
register: updated
– name: Reboot Machine if updated
command: shutdown -r +1
async: 1
poll: 0
ignore_errors: true
become: yes
when: updated.changed
– name: Wait for Machine to come back online
local_action: wait_for
host={{ inventory_hostname }}
port=22
state=started
delay=65
when: updated.changed
~