-
-
Save akram/2479276 to your computer and use it in GitHub Desktop.
Puppet class to turn parameters in to puppet resources
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
# Class: externalresources | |
# | |
# This module manages externalresources | |
# | |
# Parameters: | |
# | |
# Actions: | |
# | |
# Requires: | |
# | |
# Sample Usage: | |
# | |
# [Remember: No empty lines between comments and class definition] | |
hostclass :externalresources do | |
resourcesMap = scope.to_hash.reject { |key,value| !( key.is_a?(String) && value.is_a?(String) ) } | |
resourcesMap.keys.each do |resource| | |
resourceNameFirstChar = resourcesMap[resource][0] | |
if resourceNameFirstChar != nil && resourceNameFirstChar.chr == '{' | |
begin | |
#Convert the variable from a string to a hash | |
resourceHash = eval resourcesMap[resource] | |
rescue => e | |
notice "Couldn't convert variable #{resource} to hash: #{e}" | |
end | |
if resourceHash.has_key? :type | |
type = resourceHash[:type] | |
virtual = resourceHash.has_key? :virtual && resourceHash[:virtual] == 'true' | |
#Split out our :type parameter | |
resourceHash.reject! { |key,value| key == :type || key == :virtual } | |
#Create the virtual resource by sending it the type defined | |
begin | |
unless virtual | |
#Make our resource | |
send type.to_sym, resource, resourceHash | |
else | |
#Call our resource function and pass it to virtual | |
virtual send type.to_sym, resource, resourceHash | |
end | |
rescue => e | |
fail "Couldn't create resource #{resource}: #{e}" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment