Created
October 12, 2022 08:37
-
-
Save shakalandy/6d41c18437d96bcafad950e972c6ad10 to your computer and use it in GitHub Desktop.
ansible fact collecting nginx vhosts
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
#!/bin/bash | |
############################################### | |
# NGINX FACT | |
############################################### | |
if [ -f /usr/sbin/nginx ]; then | |
VHOSTS=$(nginx -T 2>/dev/null | grep "server_name " | awk '{print $2}' | cut -d ";" -f 1 | grep -v localhost |sort | uniq | grep -v -e '^$') | |
fi | |
FACTS="{ \"vhosts\" : [ " | |
for i in $VHOSTS; do | |
FACTS="$FACTS \"$i\" ," ; | |
done | |
############################################### | |
# Print FACTs | |
############################################### | |
echo "${FACTS%?} ] }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment