I guess one way would be to write a small custom function which gets an
array as an argument and returns an array of sources.
(didnt test :))
module Puppet::Parser::Functions
newfunction(:array2source, :type => :rvalue) do |args|
if args[0].is_a?(Array)
sources = Array.new
args[0].each {|s| source << "puppet://server/module/configfile.#{s}"}
end
sources << "puppet://server/module/configfile.default"
return sources
end
end
and then in your manifest just do:
file { "/etc/somefile.conf":
source => array2source(clusters)
}
cheers,
Ohad
On Sun, Feb 1, 2009 at 10:25 AM, threetee <[email protected]> wrote:
>
> My external node classifier returns some arrays in the list of
> parameters. Example output (names have been changed to protect the
> innocent):
>
> $ ./node_classifier a.b.com
> --- %YAML:1.0
> "classes": ["class1", "class2", "class3"]
> "parameters":
> "hostname": "a"
> "name": "a"
> "domain": "b.com"
> "fqdn": "a.b.com"
> "group": "<host group>"
> "clusters": ["cluster1", "cluster2", "cluster3", "cluster4"]
>
> In my puppet manifests, I would like to be able to use the elements in
> the clusters array to generate multiple files to use for the source
> parameter of the file type. For example, given the above YML, I'd like
> the end result of the file parameter to behave like this:
>
> file { "/etc/somefile.conf":
> source => [
> "puppet://server/module/configfile.cluster1",
> "puppet://server/module/configfile.cluster2",
> "puppet://server/module/configfile.cluster3",
> "puppet://server/module/configfile.cluster4",
> "puppet://server/module/configfile.default"
> ];
> }
>
> However, I can't figure out how to generate the multiple sources from
> the array. This (unsurprisingly) doesn't work:
>
> file { "/etc/somefile.conf":
> source => [
> "puppet://server/module/configfile.$clusters"
> ];
> }
>
> Is what I want to do here possible using the native Puppet language?
> Will I need to write a custom function to generate the source files
> myself, then pass them to the file type? Is there some other step that
> I'm just missing?
>
> Thanks in advance for any help. Getting this to work will save me a
> whole lot of time.
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---