Jordan Cabral
2013-Nov-20 13:56 UTC
[Puppet Users] How to parse same template with differen values each time
Hi, I need to parse the a template, with different values, to generate different config files in each country I need to config. The template is used inside a define, this define is used one time for each country. I need that each time y execute this define, the vars used by the template have different values, depending on the parameter "country" I cant find a nice solution for this (like using Hiera). Actually I use a custom function that loads a key/value file on my scope each time y execute de define, and I change the key/value file using the parameter "country". *Example:* define tomcat::context( $path, $country, ){ * //My custom function I want to replace* dynamicVariableCreator("context_${country}.conf") //This template needs to generate different content for each country file {"${path}_${country}.xml": content => template("context"), ensure => present, } } Thanks -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0a77e20e-8850-4bf1-835b-a62338af87e0%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Felix Frank
2013-Nov-20 16:16 UTC
Re: [Puppet Users] How to parse same template with differen values each time
Hi, you can use a hash, either from hiera or in your manifest. $config = { "country1" => { "option1" => "value1", "option2" => ... }, "country2" => { "option1" => ... } ... } In the template, you can access it like this e.g. <% data = config[country] -%> ... <ListenAddress="<%= data["option3"] %>"> ... Careful, this is untested example code. HTH, Felix On 11/20/2013 02:56 PM, Jordan Cabral wrote:> Hi, > I need to parse the a template, with different values, to generate > different config files in each country I need to config. > The template is used inside a define, this define is used one time for > each country. > I need that each time y execute this define, the vars used by the > template have different values, depending on the parameter "country" > > I cant find a nice solution for this (like using Hiera). > Actually I use a custom function that loads a key/value file on my scope > each time y execute de define, and I change the key/value file using the > parameter "country". > > _Example:_ > > define tomcat::context( > $path, > $country, > ){ > > *//My custom function I want to replace* > dynamicVariableCreator("context_${country}.conf") > > //This template needs to generate different content for each country > file {"${path}_${country}.xml": > content => template("context"), > ensure => present, > } > > } > > Thanks-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/528CE072.6050706%40alumni.tu-berlin.de. For more options, visit https://groups.google.com/groups/opt_out.
Jordan Cabral
2013-Nov-20 18:31 UTC
Re: [Puppet Users] How to parse same template with differen values each time
I tried that, but in that way I cant override internal vars of the hash (option1) in different files of the hiera hierarchy, because I need to ask to hiera for the entire hash. El miércoles, 20 de noviembre de 2013 13:16:50 UTC-3, Felix.Frank escribió:> > Hi, > > you can use a hash, either from hiera or in your manifest. > > $config = { > "country1" => { "option1" => "value1", "option2" => ... }, > "country2" => { "option1" => ... } > ... > } > > In the template, you can access it like this e.g. > > <% data = config[country] -%> > ... > <ListenAddress="<%= data["option3"] %>"> > ... > > Careful, this is untested example code. > > HTH, > Felix > > On 11/20/2013 02:56 PM, Jordan Cabral wrote: > > Hi, > > I need to parse the a template, with different values, to generate > > different config files in each country I need to config. > > The template is used inside a define, this define is used one time for > > each country. > > I need that each time y execute this define, the vars used by the > > template have different values, depending on the parameter "country" > > > > I cant find a nice solution for this (like using Hiera). > > Actually I use a custom function that loads a key/value file on my scope > > each time y execute de define, and I change the key/value file using the > > parameter "country". > > > > _Example:_ > > > > define tomcat::context( > > $path, > > $country, > > ){ > > > > *//My custom function I want to replace* > > dynamicVariableCreator("context_${country}.conf") > > > > //This template needs to generate different content for each country > > file {"${path}_${country}.xml": > > content => template("context"), > > ensure => present, > > } > > > > } > > > > Thanks >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5da45387-847d-4b66-8c7d-51a80eab1677%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Felix Frank
2013-Nov-20 21:55 UTC
Re: [Puppet Users] How to parse same template with differen values each time
Yes, that''s a limitation you get from relying on hashes in your hierarchy. Tough call. Of course, you *could* override the entire hash where necessary. Or, you could cut out the top level of the hash and make each hash key a hiera key instead: countrydata_us: option1: option2: ... countrydata_uk: option1: ... ... This way you may get away with overriding only select countries. But I suggest you share more information about your data model, especially wrt. your hierarchical overriding needs. Perhaps we can find a more sensible approach for the problem as a whole. Cheers, Felix On 11/20/2013 07:31 PM, Jordan Cabral wrote:> I tried that, but in that way I cant override internal vars of the hash > (option1) in different files of the hiera hierarchy, > because I need to ask to hiera for the entire hash.-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/528D2FD5.1050108%40Alumni.TU-Berlin.de. For more options, visit https://groups.google.com/groups/opt_out.