Last active
August 29, 2015 14:19
-
-
Save acidprime/1d6d0f23c1d52fcc2c35 to your computer and use it in GitHub Desktop.
Use resource_type to retrieve native ruby objects you can use with to_yaml
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
#!/opt/puppet/bin/ruby | |
require 'puppet/face' | |
require 'yaml' | |
Puppet.parse_config | |
resources = Puppet::Face[:resource_type, '0.0.1'].search('.*',{:extra => { 'environment' => 'production' }}) | |
output = Hash.new | |
resources.each do |resource| | |
resource.arguments.each do |k,v| | |
case v.class.to_s | |
when "Puppet::Parser::AST::String" | |
result = v.evaluate('subscope') | |
when "Puppet::Parser::AST::Undef" | |
# "We don't support undef values..." | |
next | |
when "Puppet::Parser::AST::Variable" | |
result = "%{#{v.to_s[1..-1]}}" | |
when "Puppet::Parser::AST::ASTHash" | |
result = v.evaluate('subscope') | |
break if result.empty? | |
when "Puppet::Parser::AST::ASTArray" | |
result = v.evaluate('subscope') | |
when "Puppet::Parser::AST::Boolean" | |
result = v.evaluate('subscope') | |
else | |
# "We don't support raw puppet code..." | |
next | |
end | |
output["#{resource.name}::#{k.to_s}"] = result | |
end | |
end | |
puts output.to_yaml |
Author
acidprime
commented
Apr 17, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment