On 05/06/16 19:56, Robert Poulson wrote:
Dear List,
I've been using Puppet for over a year now and I'm quite enjoying it.
I've learned some stuff but there is of course always room for
improvement. Now I have a task which needs a nicer solution than I'm
currently capable of.
I have a hash of items with to key/value pairs, which is *the same for
every node*:
$input_base => {
input1 => { 'port' => '2001', 'component' => 'component1' },
input2 => { 'port' => '2002', 'component' => 'component2' }
}
Then I have a second hash, which is different for every node.
$input_node => {
input3 => { 'port' => '2003', 'component' => 'component3' },
[possibly input4... inputN]
}
These all will be used in a single template. So I can simply do:
$input_merged = merge($input_base, $input_node)
The corresponding port/component entries will then be added in a
configuration file with an $input_merged.each_pair - so far so good.
Now the actual task: I need an extra configfile, generated from a
template, for all the inputN elements of the $input_node - but only for
them, not for the $input_base elements - like this:
* /path/to/project_input3.conf
* [/path/to/project_input4.conf...project_inputN.conf]
This would be possible with create_resources:
create_resources(file, $input_merged)
but in order to do this, $input_merged should have the values of a file
resource - at least "path" and "source => template()". This is not the case.
I could define $input_node initially as a file resource hash - but in
this case I can't merge it anymore with $input_base.
Currently I have no other idea than manually map the input_node elements
into a third hash, and use that with create_resources, but there should
be a nicer solution. Do you have an idea? :-)
If you are using 3.x with future parser, or if you are on 4.x it may be
easier to use iteration over the hash(es).
$input_merged.each |$input, $options| {
file { "/path/to/project_${input}.conf":
source => template(),
# etc...
}
}
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
You received this message because you are subscribed to the Google Groups "Puppet
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/26385ea9-102b-0b76-518d-4c983ac798a4%40puppet.com.
For more options, visit https://groups.google.com/d/optout.