Always reboot if reboot is run

This commit is contained in:
Sam A. 2023-08-05 14:18:35 +02:00
parent f0cd39728a
commit ce7e6ffc5e
Signed by: samsapti
GPG key ID: CBBBE7371E81C4EA
2 changed files with 10 additions and 22 deletions

View file

@ -4,16 +4,16 @@ set -e
usage() {
printf '%s\n' "Usage:"
printf '$ %s\n' "$0 [-h|--help]"
printf '$ %s\n' "$0 [--help]"
printf '$ %s\n' "$0 [--dry] os"
printf '$ %s\n' "$0 [--dry] base"
printf '$ %s\n' "$0 [--dry] firewall"
printf '$ %s\n' "$0 [--dry] ssh"
printf '$ %s\n' "$0 [--dry] docker"
printf '$ %s\n' "$0 [--dry] docker_config"
printf '$ %s\n' "$0 [--dry] users [-i|--init]"
printf '$ %s\n' "$0 [--dry] reboot [-f|--force]"
printf '$ %s\n' "$0 [--dry] services [-d|--down] [SINGLE_SERVICE]"
printf '$ %s\n' "$0 [--dry] users [--init]"
printf '$ %s\n' "$0 [--dry] reboot"
printf '$ %s\n' "$0 [--dry] services [--down] [SINGLE_SERVICE]"
}
install_modules() {
@ -45,25 +45,18 @@ case $TAG in
users)
install_modules
if [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
if [ "$1" = "--init" ]; then
$EXEC "$BASE_CMD --user root --tags '$TAG'"
else
$EXEC "$BASE_CMD --tags '$TAG'"
fi
;;
reboot)
install_modules
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'force_reboot=true'"
else
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'reboot=true'"
fi
;;
install_modules; $EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'do_reboot=true'" ;;
services)
install_modules
if [ "$1" = "-d" ] || [ "$1" = "--down" ]; then
if [ "$1" = "--down" ]; then
DOWN=1
shift
fi
@ -78,7 +71,7 @@ case $TAG in
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
;;
-h|--help)
--help)
usage ;;
*)
usage >&2; exit 1 ;;

View file

@ -14,19 +14,14 @@
vars:
stop: true
when: needs_reboot.stat.exists or
(force_reboot is defined and force_reboot)
(do_reboot is defined and do_reboot)
- name: Reboot host
ansible.builtin.reboot:
when: needs_reboot.stat.exists or
(force_reboot is defined and force_reboot)
(do_reboot is defined and do_reboot)
register: rebooted
- name: End play if reboot is not needed
ansible.builtin.meta: end_play
when: reboot is defined and reboot and
(rebooted.rebooted is undefined or not rebooted.rebooted)
- name: Re-gather facts
ansible.builtin.setup:
filter: