From ce7e6ffc5e88f5a80ac566de989a3ac2857122b7 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Sat, 5 Aug 2023 14:18:35 +0200 Subject: [PATCH] Always reboot if reboot is run --- provision.sh | 23 ++++++++--------------- roles/os_config/tasks/reboot.yml | 9 ++------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/provision.sh b/provision.sh index 8322a4c..7e9af8c 100755 --- a/provision.sh +++ b/provision.sh @@ -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 ;; diff --git a/roles/os_config/tasks/reboot.yml b/roles/os_config/tasks/reboot.yml index a40fc99..44a5470 100644 --- a/roles/os_config/tasks/reboot.yml +++ b/roles/os_config/tasks/reboot.yml @@ -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: