On Mon, Oct 17, 2011 at 3:57 PM, Matt <[email protected]> wrote:
> So I am messing around with puppet dashboard and for the most part for
> what I am working on it fits the bill for an ENC. The only question I
> have is I need to pass information about a customer to set up
> resources and the system can have multiple customers on it. What is
> the best way to handle complex data? Would I be able to pass json data
> for example?
This is stolen from some doc I wrote for how to support complex data
in dashboard until is has hash/array support. Missing pictures, but
should have everything you need on how to use json data in dashboard.
In puppetlabs-stdlib we added several functions including parseyaml,
and parsejson for this purpose. Unfortunately there’s one more hurdle
since the data passed back from dashboard is pading single \ to triple
\\\ as well as striping leading ---, so this requires us to convert
“[\\\“0.pool.ntp.org\\\”]” to “[\”0.pool.ntp.org\”]”. To get around
this we do a quick data cleanup with the following function:
module Puppet::Parser::Functions
newfunction(:convjson, :type => :rvalue) do |args|
if args[0].to_s.empty? then
fail "Must provide non empty value."
else
return args[0].gsub(/\\/,'')
end
end
end
At this point you can convert the json string back to an array/hash in puppet:
class ntp(
$ntp_server=parsejson(convjson($::ntp_server))
) {
file {'/etc/ntp.conf':
...
# template use $ntp_server
content => template('ntp/ntp.conf.erb'),
}
service {'ntpd':
...
}
}
Thanks,
Nan
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.