- name: Create update Script copy: dest: /usr/local/bin/nightly-update.sh content: | #!/bin/bash { echo "Starting update at $(date)" apt-get update -q apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold dist-upgrade --auto-remove echo "Update completed at $(date)" } >> "/var/log/nightly-update.log" 2>&1 shutdown -r now mode: '0755' - name: Ensure at is installed apt: name: at state: present - name: Ensure atd (at daemon) is running and enabled service: name: atd state: started enabled: true - name: Schedule nightly-update.sh to run between 5:00-6:59 AM once shell: | hour=$(shuf -i 5-6 -n 1) minute=$(shuf -i 0-59 -n 1) echo "/usr/local/bin/nightly-update.sh" | at "$hour:$minute" echo "update and restart scheduled for $hour:$minute" register: restard_scheduled - name: output "restart schedule" debug: var: restard_scheduled.stdout_lines