add nightly_update role
This commit is contained in:
parent
cfcad80523
commit
c642012754
3 changed files with 41 additions and 1 deletions
|
@ -6,6 +6,10 @@
|
|||
import_tasks: update.yml
|
||||
tags: update
|
||||
|
||||
- name: schedule package update and restart for the night
|
||||
import_tasks: nightly_update.yml
|
||||
tags: nightly_update
|
||||
|
||||
- name: restart server if required
|
||||
import_tasks: restart.yml
|
||||
tags: restart
|
||||
|
|
36
tasks/nightly_update.yml
Normal file
36
tasks/nightly_update.yml
Normal file
|
@ -0,0 +1,36 @@
|
|||
- 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
|
|
@ -1,4 +1,4 @@
|
|||
- name: schedule restart randomly between 2-5 AM if necessary
|
||||
- name: schedule restart randomly between 5-7 AM if necessary
|
||||
shell: |
|
||||
hour=$(shuf -i 5-6 -n 1)
|
||||
minute=$(shuf -i 0-59 -n 1)
|
||||
|
|
Loading…
Add table
Reference in a new issue