Skip to content

Instantly share code, notes, and snippets.

@shakalandy
Created October 12, 2022 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakalandy/6d41c18437d96bcafad950e972c6ad10 to your computer and use it in GitHub Desktop.
Save shakalandy/6d41c18437d96bcafad950e972c6ad10 to your computer and use it in GitHub Desktop.
ansible fact collecting nginx vhosts
#!/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