El lunes, 6 de octubre de 2014 10:52:05 UTC-3, jcbollinger escribió:
>
>
>
> On Sunday, October 5, 2014 5:55:55 PM UTC-5, Ciro Iriarte wrote:
>>
>> Hi!, I'm starting to work with hiera and file templates, how would be the 
>> best way to transform this hiera output:
>>
>> myanycast::bird::ospf:
>>   myinstance:
>>     tick: 2
>>     rfc1583compat: 'yes'
>>     export: 'all'
>>     area:
>>       990:
>>         stub: 'no'
>>         interface:
>>           eth0:
>>             hello: 10
>>             retransmit: 6
>>             cost: 10
>>             transmit_delay: 5
>>             dead_count: 5
>>             dead: 40
>>             wait: 50
>>             type: 'broadcast'
>>
>> To this in the final configuration file using templates?:
>>
>> protocol ospf myinstance:
>>   tick 2;
>>   yes;
>>   export all;
>>   area 990 {
>>     stub no;
>>     interface "eth0" {
>>       hello 10;
>>       retransmit 6;
>>       cost 10;
>>       transmit delay 5;
>>       dead count 5;
>>       dead 40;
>>       wait 50;
>>       type broadcast;
>>       };
>>   };
>> }
>>
>> There can be many areas per instance, and many interfaces per area.
>>
>
>
> If you haven't already, you should read the documentation 
> <https://docs.puppetlabs.com/guides/templating.html>.  Here's a partial 
> implementation to give you the idea:
>
> modules/manycast/manifests/bird.pp
> ----
> class manycast::bird(
>   $ospf,
>   # ...
> ) {
>   # Not sure what file you want to manage...
>   file { '/etc/bird/ospf.conf':
>     ensure => 'file',
>     content => template('manycast/ospf.conf.erb'),
>     # ...
>   }
> }
>
>
> modules/manycast/templates/ospf.conf.erb
> ----
> <%
>   @ospf.sort.each_pair do | instance, instance_data |
> -%>
> protocol ospf <%= instance %>:
>   tick <%= instance_data.tick %>;
>   <%= instance_data.rfc1583compat %>;
>   export <%= instance_data.export %>;
> <%
>     instance_data.area.sort.each_pair do | area, area_details |
> -%>
>   area <%= area %> {
>     stub <%= area_details.stub %>;
> <%
>
> * # Fill in the rest ...*-%>
>   };
> <%
>     end
>   end if @ospf and @ospf.is_a Hash
>  -%>
>
>
>
>> Also, something that I noticed about hashes is that each hiera query (at 
>> least by hand) gives me the same data in different order. Can this trigger 
>> a different md5 for the file and force a service reload each 30 minutes 
>> even there are no configuration changes?
>>
>
>
> Yes, reordering the content of a file changes its MD5.  If you have a 
> service that receives events from this file, then such a reordering will 
> cause Puppet to restart the service.  Even if not, one generally wants to 
> avoid the noise arising from meaningless resource modifications.  That is 
> the template's purpose for sorting the hashes.
>
>
> John
>
>
Trying this approach I get "Detail: undefined method `each_pair' for 
#<Array:0x7f19bc81d288>" using this code:


<% if (@ospfconfig.is_a?(Hash)) and (@ospfconfig.count > 0) -%>
<% @ospfconfig.sort.each do |instance,instparam| -%>
protocol ospf <%= instance %> {

}
<% end -%>
<% end -%>

Can it be a Ruby version thing?

Regards,
Ciro

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/3fc2f5c1-532a-4de0-b461-10708dd5d9df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to