Skip to content

Instantly share code, notes, and snippets.

@frozenfoxx
Created April 21, 2016 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozenfoxx/79929a21fcc4824fdb6023513b7c66ac to your computer and use it in GitHub Desktop.
Save frozenfoxx/79929a21fcc4824fdb6023513b7c66ac to your computer and use it in GitHub Desktop.
# Variables
CERTS=''
PUPPET=/opt/puppetlabs/bin/puppet
CERTFILES=/etc/puppetlabs/puppet/ssl/ca/signed
PREFIX=<%= @prefix %>
# Logic
CERTS=$(${PUPPET} cert list --all | grep -e "^\+\s\"${PREFIX}.*$" | cut -f 2 -d ' ' | sed 's/\"//g')
echo "Found $(echo ${CERTS} | wc -w) ephemeral clone certificates."
# Loop through the found certificates
for cert in ${CERTS}; do
LOOKUP=$(nslookup ${cert})
# If it doesn't exist, purge it
if [ $? -eq 0 ] ; then
echo "${cert} is online."
else
echo "${cert} offline. Purging..."
echo "Removing ${CERTFILES}/${cert}.pem..."
rm ${CERTFILES}/${cert}.pem
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment