Improve emitter and time stamping.

The emitter failed to keep book on hosts where ansible did not succeed.
This commit is contained in:
Andreas B. Mundt 2024-02-20 16:35:54 +01:00
parent 37e4108021
commit 665109ef55
3 changed files with 171 additions and 169 deletions

View file

@ -28,7 +28,6 @@ echo "Time stamp at: $timestamp."
#dir="$(mktemp -d)"
dir="/tmp/emitter"
mkdir -vp "$dir"
touch "$dir/${timestamp//T*/}"
hlist=""
n=0
@ -51,24 +50,23 @@ find_outdated(){
if [[ -z "$ipa" ]] ; then
# FIXME: Outdated report format, try fallback:
ipa="$(sed -nE "s|^.+default via.+ src ($r) metric.+|\1|p" "$file" | head -1)"
echo -ne "\n Outdated '$ipa': $file"
fi
$debug && echo "'$ipa'."
if ! grep -q "$ipa" "$dir/${timestamp//T*/}" ; then
echo "$ipa" >> "$dir/${timestamp//T*/}"
hlist="$hlist,$ipa"
n=$(( n + 1 ))
if [[ $(date --date="$d" +%s) -lt $(date --date="$git_date" +%s) ]] ; then
## ansible run needed at least on one machine, run it on all:
echo "Triggering full ansible run!"
ansible_arg=""
fi
hlist="$hlist,$ipa"
n=$(( n + 1 ))
if [[ $(date --date="$d" +%s) -lt $(date --date="$git_date" +%s) ]] ; then
## ansible run needed at least on one machine, run it on all:
echo -n "✗"
ansible_arg=""
else
$debug && echo "Host already processed before."
echo -n "U"
fi
else
echo -n '✓'
fi
done < <(find "$logdir" -maxdepth 1 -type f -mmin -$age -print0)
hlist="${hlist#,}"
echo -n "Running hosts: $running, to be upgraded: $n. "
echo -n " $n/$running "
}
run_ansible(){
@ -78,8 +76,7 @@ run_ansible(){
ansible-playbook --vault-password-file ~/.vaultpwd \
-bi inventory.yml "$pbook.yml" "$ansible_arg" -l "$hsts" ; then
while IFS= read -r ipa ; do
sed -i "/$ipa/d" "$dir/${timestamp//T*/}"
echo "IP address '$ipa' removed from '$dir/${timestamp//T*/}'."
echo "Ansible for IP address '$ipa' failed."
done < "$dir/$pbook.retry"
fi
fi
@ -87,10 +84,10 @@ run_ansible(){
#################
while true ; do
date --rfc-3339=seconds
date +%H:%M | tr '\n' ' '
find_outdated
run_ansible "$hlist"
t=$(( 600/(n*n+1) ))
echo -n "Sleeping for $t seconds now ... "
echo "sleeping ${t}s "
sleep $t
done