diff --git a/deploy.sh b/deploy.sh index 746d665..0d478ff 100755 --- a/deploy.sh +++ b/deploy.sh @@ -2,7 +2,7 @@ usage () { echo "Usage: $0" - echo "Usage: $0 boot" + echo "Usage: $0 reboot [-f|--force]" echo "Usage: $0 services [SINGLE_SERVICE]" } @@ -16,8 +16,12 @@ if [ -z "$1" ]; then $BASE_CMD else case $1 in - boot) - $BASE_CMD --tags boot + reboot) + if [ "$2" = "-f" ] || [ "$2" = "--force" ]; then + $BASE_CMD --tags reboot --extra-vars "force_reboot=true" + else + $BASE_CMD --tags reboot + fi ;; services) if [ -z "$2" ]; then diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 3e2cf83..12990c7 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -40,5 +40,5 @@ - name: Set up Docker services import_tasks: services.yml tags: - - boot + - reboot - services diff --git a/roles/os_config/tasks/main.yml b/roles/os_config/tasks/main.yml index 3d824f1..bc8a97f 100644 --- a/roles/os_config/tasks/main.yml +++ b/roles/os_config/tasks/main.yml @@ -12,7 +12,12 @@ - name: Configure SSH import_tasks: ssh.yml +- name: Reboot if needed + import_tasks: reboot.yml + tags: + - reboot + - name: Configure disks import_tasks: disks.yml tags: - - boot + - reboot diff --git a/roles/os_config/tasks/reboot.yml b/roles/os_config/tasks/reboot.yml new file mode 100644 index 0000000..c9fdf39 --- /dev/null +++ b/roles/os_config/tasks/reboot.yml @@ -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)