From 9372ce5a85132d00289b95f6b59031f82fa777e0 Mon Sep 17 00:00:00 2001 From: kneutron <50146127+kneutron@users.noreply.github.com> Date: Wed, 27 Apr 2022 13:07:00 -0500 Subject: [PATCH] Add files via upload --- ans-reboot-server-copypasta.sh | 26 ++++++++++++++++++++++++++ ans-reboot-server.sh | 12 ++++++++++++ reboot-and-wait.yml | 15 +++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 ans-reboot-server-copypasta.sh create mode 100644 ans-reboot-server.sh create mode 100644 reboot-and-wait.yml diff --git a/ans-reboot-server-copypasta.sh b/ans-reboot-server-copypasta.sh new file mode 100644 index 0000000..ec7bf6e --- /dev/null +++ b/ans-reboot-server-copypasta.sh @@ -0,0 +1,26 @@ +#!/bin/bash5 + +# Paste a vertical list of servers separated by newline +# ^ pass them as comma-separated server(s) to ansible; reboot and wait up to 10 min + +echo "Paste vertical list of servers / IP addresses; Enter EOF at the end of server list to begin processing" + +buildstr="" +while read inline; do + [ "$inline" = "EOF" ] && break; + + fstchr=${inline:0} + if [[ $fstchr =~ ^[0-9] ]] && [ $(echo $inline |awk '{sum+=gsub(/\./,"")}END{print sum}') -eq 3 ]; then +# 1st char=number and contains 3 dots, more than likely an IPV4 addr + buildstr="$buildstr$inline," + else + hnonly=${inline%%.*} # strip evyting after first dot, dont need FQDN + hnonly=${hnonly,,} # and lowercase it + buildstr="$buildstr$hnonly," + fi +done +buildstr=$(echo ${buildstr%,}) # omit trailing comma + +servers=$buildstr +echo "$buildstr" +ansible-playbook reboot-and-wait.yml --become -e "target=$servers" diff --git a/ans-reboot-server.sh b/ans-reboot-server.sh new file mode 100644 index 0000000..ba5f02d --- /dev/null +++ b/ans-reboot-server.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# pass comma-separated server(s) as arg; reboot and wait up to 10 min +if [ "$1" = "" ]; then + echo "Provide at least one target server as parameter" + exit 404; +else + servers=${@%,} # omit trailing comma + echo "$servers" + ansible-playbook reboot-and-wait.yml --become -e "target=$servers" +fi + diff --git a/reboot-and-wait.yml b/reboot-and-wait.yml new file mode 100644 index 0000000..a819ded --- /dev/null +++ b/reboot-and-wait.yml @@ -0,0 +1,15 @@ +--- + +- hosts: '{{target}}' + tasks: + - name: reboot and wait + become: yes + reboot: + reboot_timeout: 600 + +- - name: check uptime + register: uptimeoutput + command: "uptime" + + - debug: + var: uptimeoutput.stdout_lines