Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
Created July 1, 2015 04:41
Show Gist options
  • Select an option

  • Save GeoffWilliams/aa6394a825ffd52b10e4 to your computer and use it in GitHub Desktop.

Select an option

Save GeoffWilliams/aa6394a825ffd52b10e4 to your computer and use it in GitHub Desktop.
Refresh known classes in puppet using the NC API
#!/bin/bash
#
# This script will force a refresh of the classes available to use in the
# PE Node Classifier. This enables us to classify immediately, rather than
# waiting for the cache to expire.
#
# refresh_classes.sh
#
if [ "$#" -ne 0 ]
then
echo "This script takes no arguments."
exit 1
fi
function refresh()
{
set -e
set -u
CONFDIR='/etc/puppetlabs/puppet'
CERT=$(puppet master --confdir ${CONFDIR} --configprint hostcert)
CACERT=$(puppet master --confdir ${CONFDIR} --configprint localcacert)
PRVKEY=$(puppet master --confdir ${CONFDIR} --configprint hostprivkey)
OPTIONS="--cert ${CERT} --cacert ${CACERT} --key ${PRVKEY}"
CONSOLE=$(awk '/server =/{print $NF}' ${CONFDIR}/console.conf)
curl -s -k -X POST ${OPTIONS} "https://${CONSOLE}:4433/classifier-api/v1/update-classes" & disown
}
# only run one copy at a time
if [ ! "$(/sbin/pidof -x curl)" ]
then
echo "Updating list of classes available in the Node Classifier..."
refresh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment