-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a column to show whether host is added to ssh config.
- Loading branch information
1 parent
7fd60ee
commit 7b52fbe
Showing
1 changed file
with
14 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |