Reboot host if needed or if forced

This commit is contained in:
Sam A. 2022-12-25 18:12:45 +01:00
parent c85fdf12b5
commit 5decde69dc
Signed by: samsapti
GPG key ID: CBBBE7371E81C4EA
4 changed files with 26 additions and 5 deletions

View file

@ -2,7 +2,7 @@
usage () { usage () {
echo "Usage: $0" echo "Usage: $0"
echo "Usage: $0 boot" echo "Usage: $0 reboot [-f|--force]"
echo "Usage: $0 services [SINGLE_SERVICE]" echo "Usage: $0 services [SINGLE_SERVICE]"
} }
@ -16,8 +16,12 @@ if [ -z "$1" ]; then
$BASE_CMD $BASE_CMD
else else
case $1 in case $1 in
boot) reboot)
$BASE_CMD --tags boot if [ "$2" = "-f" ] || [ "$2" = "--force" ]; then
$BASE_CMD --tags reboot --extra-vars "force_reboot=true"
else
$BASE_CMD --tags reboot
fi
;; ;;
services) services)
if [ -z "$2" ]; then if [ -z "$2" ]; then

View file

@ -40,5 +40,5 @@
- name: Set up Docker services - name: Set up Docker services
import_tasks: services.yml import_tasks: services.yml
tags: tags:
- boot - reboot
- services - services

View file

@ -12,7 +12,12 @@
- name: Configure SSH - name: Configure SSH
import_tasks: ssh.yml import_tasks: ssh.yml
- name: Reboot if needed
import_tasks: reboot.yml
tags:
- reboot
- name: Configure disks - name: Configure disks
import_tasks: disks.yml import_tasks: disks.yml
tags: tags:
- boot - reboot

View file

@ -0,0 +1,12 @@
# vim: ft=yaml.ansible
---
- name: Check if reboot is needed
stat:
path: /var/run/reboot-required
register: needs_reboot
- name: Reboot host
reboot:
connect_timeout: 60
when: needs_reboot.stat.exists or
(force_reboot is defined and force_reboot)