Skip to content

Commit

Permalink
Update nodes list script
Browse files Browse the repository at this point in the history
Add a column to show whether host is added to ssh config.
  • Loading branch information
sorrowless committed Feb 2, 2024
1 parent 7fd60ee commit 7b52fbe
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tools/nodes_list.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#!/bin/bash
set -ux

# We control target directory carefully, so no need in 'read/while' loop here
# and overall complexity.
# shellcheck disable=SC2044
for i in $(find host_vars -not -path '*host_vars/.*' -type f -iname '*.yml') ; do
for i in $(find -E host_vars -not -path '*host_vars/.*' -type f -regex '.*(main|common).yml') ; do
# shellcheck disable=SC2016
grep -q '$ANSIBLE_VAULT;' "$i"
rc=$?
if [[ $rc -ne 0 ]]; then
hostname=$(echo $i | cut -d '/' -f 2)
placement=$(grep placement "$i" | cut -d ":" -f 2)
hostname=$(echo "$i" | cut -d '/' -f 2)
placement=$(grep placement "$i" | cut -d ":" -f 2 | awk '{$1=$1};1')
host=$(grep 'ansible_host: ' "$i" | cut -d ":" -f 2)
ip=$(grep 'ansible_ip: ' "$i" | cut -d ":" -f 2)
if [[ -z "$ip" ]]; then
ip=$host
fi
if command -v shost &> /dev/null; then
if [[ -n "$ip" ]]; then
if shost $ip >/dev/null; then
additional_data="\tFound in SSH config"
else
additional_data="\tNot found in SSH config"
fi
fi
fi
if [[ -n "$host" ]]; then
i=${i##*/}
name=${i%.*}
echo -e "$hostname\t$ip\t$host\t$name\t$placement"
echo -e "$hostname\t$ip\t$host\t${placement// /-}${additional_data// /-}"
fi
fi
done | column -t

0 comments on commit 7b52fbe

Please sign in to comment.