#!/usr/bin/bash ### # User variables, you may edit these variables ### SOURCES=$HOME/park-admin/playbooks-ansible WORKDIR=/tmp COUNTLIMIT=10 # Availables options are: 'clearnet' or 'tornetwork' NETWORK=clearnet FORK=8 TIMEOUT=240 FLAGS="--force-handlers -f $FORK -T $TIMEOUT" ### # Stop editing, it is ready ### # sortie formatée des logs OK="\e[0m[ \e[92mOK\e[0m ]" ERROR="\e[0m[ \e[91mERROR\e[0m ]" INFO="\e[0m[ \e[93mINFO\e[0m ]" ### # User command-line options ### while [[ $# -gt 0 ]] do case "$1" in -d|--debug) COUNTLIMIT=2 shift ;; *) echo "Usage: $0 [-d|--debug]" exit 3 ;; esac done ### # End ### REPLAY=true COUNT=1 pushd $WORKDIR >/dev/null if [[ $NETWORK == "clearnet" ]] then CMDLINE=ansible-playbook HOSTFILE=$SOURCES/hosts.net elif [[ $NETWORK == "tornetwork" ]] then CMDLINE="torsocks ansible-playbook" HOSTFILE=$SOURCES/hosts.tor fi # need cleanup before starting loop if [[ -f $SOURCES/site.retry ]] then rm -f $SOURCES/site.retry echo -e "$ERROR retry file found, cleaning up..." else echo -e "$OK retry file not found, starting loop..." fi while [[ $REPLAY == "true" ]] && [[ $COUNT -lt $COUNTLIMIT ]] do if [[ -f $SOURCES/site.retry ]] then LIMIT="--limit @${SOURCES}/site.retry" echo -e "$OK retry file found" else LIMIT="" echo -e "$INFO retry file not found" fi if ( $CMDLINE $FLAGS -i $HOSTFILE $LIMIT $SOURCES/site.yml ) then REPLAY=false else # no infinite loop COUNT=$((COUNT + 1)) fi done popd >/dev/null echo -e "$OK End of Replay" echo -e "$INFO Replay launched $COUNT times" echo -e "$OK Have a nice day $USER !"