Articles‎ > ‎Puppet‎ > ‎

Puppet autoclassifier

If you have environment or network information somehow encoded into hostname you might have a chance to have zero maintenance puppet server config. All you need is to write autoclassifier script and plug it in into puppet server config. Lets create script which will look something like this:
h=`echo $1 | cut -f1 -d.`
if [ "z${h}" == "zdefault" ]; then
      echo '---'
      echo 'classes:'
      echo " - default"
      exit 0
elif [ `echo ${h} | grep -c '^sea'` -eq 1 ] ; then
elif [ `echo ${h} | grep -c '^sfa'` -eq 1 ] ; then
      exit 1
#   echo "  - ${h}"
echo '---'
echo 'classes:'
echo "  - ${office}-office"
exit 0

Test script by supplying host name to it as parameter, check that script has valid YAML output. Save script somewhere in /etc/puppet/scripts/, define this script in /etc/puppet/puppet.conf in [puppetmasterd] section as external_nodes=/etc/puppet/scripts/ Now all you need to do is to define all you classes in site.pp (don't forget to define default class) then enjoy servers being automatically assigned to classes based on regexp against their hostname.