Created
November 30, 2010 20:27
-
-
Save glarizza/722336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # | |
| # | |
| # This External Node classifier script will return appropriate classes for Puppet depending | |
| # on the machine's huron_class fact. The script will dip into the Server's YAML depository, | |
| # search for the passed certname, extract the fact information, and return a YAML block to | |
| # puppet. | |
| # | |
| # Created by Gary Larizza - 6.10.2010 | |
| # Last Modified - 11.30.2010 | |
| # | |
| # | |
| require 'yaml' | |
| require 'puppet' | |
| # Intitialize Variables | |
| vardir = "/var/lib/puppet/yaml/facts/" | |
| default = {'classes' => []} | |
| yaml_output = {} | |
| # Check to see if the Node YAML file exists. | |
| # If it exists, set the huron_class variable to that fact's value | |
| begin | |
| yamlfile = YAML::load_file(vardir + ARGV[0] + '.yaml').values | |
| huron_class = yamlfile["huron_class"] | |
| environment = yamlfile["environment"] | |
| rescue Exception => error | |
| puts "Node YAML file was not found! Error: " + error | |
| exit(1) | |
| end | |
| # If huron_class is nil, escape with a blank YAML output | |
| if huron_class.nil? | |
| print default.to_yaml | |
| exit(0) | |
| end | |
| # Output our classes and environment values to YAML for Puppet | |
| yaml_output = {'classes' => huron_class.split(','), 'environment' => environment} | |
| print yaml_output.to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment