Skip to content

Instantly share code, notes, and snippets.

@ccaum
Created December 1, 2010 22:21
Show Gist options
  • Save ccaum/724339 to your computer and use it in GitHub Desktop.
Save ccaum/724339 to your computer and use it in GitHub Desktop.
Puppet class to turn parameters in to puppet resources
hostclass :externalresources do
scope_h = scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }
scope_h.keys.each do |var|
if scope_h[var][0].chr == '{'
begin
#Convert the variable from a string to a hash
var_h = eval scope_h[var]
rescue => e
notice "Couldn't convert variable #{var} to hash: #{e}"
end
if var_h.has_key? :type
type = var_h[:type]
virtual = var_h.has_key? :virtual and var_h[:virtual] == 'true'
#Split out our :type parameter
var_h.reject! { |k,v| k == :type or k == :virtual }
#Create the virtual resource by sending it the type defined
begin
unless virtual
#Make our resource
send type.to_sym, var, var_h
else
#Call our resource function and pass it to virtual
virtual send type.to_sym, var, var_h
end
rescue => e
fail "Couldn't create resource #{var}: #{e}"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment