Report abuse

bash-3.2# cat /usr/bin/puppet_external_nodes.sh 
#!/bin/bash
#
#  Script that checks out the passed hostname and determines the correct classes
#  
#  Hostnames are parsed:  machinename-machinetype-building with either .local or .huronhs.com ending
#
#  If a hostname does not conform to the hyphenated standard, it receives a non-zero error type
#    and is passed back to the nodes.pp file in Puppet.
#

hostname=$1

#  Extract machinename, machinetype, and building codes

one=`echo $hostname | awk -F'-' '{print $1}'`
two=`echo $hostname | awk -F'-' '{print $2}'`
three=`echo $hostname | awk -F'-' '{print $3}' | sed 's/\..*//'`

#  If the machine does not conform to the hyphenated standard, pass a non-zero error
#    and return us to the main nodes.pp file.

if [ -z "$two" ] && [ "${two+xxx}" = "xxx" ]; then
	exit 1
fi

#  If the machine DOES conform to the hyphenated standard, pass the machinetype and
#     building variables as classtypes in Puppet.  Exit 0 to appease Puppet

cat << END
---
classes:
        - general_image
        - $two
        - $three
parameters:
        puppet_server: testing.huronhs.com
END

exit 0