Doing create_resources(''file'',hiera_hash(''input'')) works great for some hiera like input: /tmp/a.txt: owner: root ensure: file ... Im not able to put any template() stuff in there input: /tmp/a.txt: owner: root ensure: file content: template("create_re/aha.erb") Instead of doing the template lookup. The content of the file is ''template("create_re/aha.erb")'' Any way to dynamically (hiera) define the templates? Regards Erkan -- über den grenzen muß die freiheit wohl wolkenlos sein -- 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/1ViPtj-0001TZ-1c%40linsenraum.de. For more options, visit https://groups.google.com/groups/opt_out.
Hi, tough call. You may have to replicate the file type in a defined type like so: define my_file($owner="root",$mode="644",...,$template="") { if $template { File[$name] { content => template($template) } } file { $name: owner => $owner, ... } } Then you can create_resource(''my_file'',hiera(''input'')) and pass an actual "template" parameter to your define. Lots of work, but I feel that at some points, many if not most users likely feel the need to wrap the file type this way. HTH, Felix On 11/18/2013 03:33 PM, erkan yanar wrote:> Doing create_resources(''file'',hiera_hash(''input'')) > works great for some hiera like > input: > /tmp/a.txt: > owner: root > ensure: file > ... > > Im not able to put any template() stuff in there > input: > /tmp/a.txt: > owner: root > ensure: file > content: template("create_re/aha.erb") > > Instead of doing the template lookup. The content of the file is > ''template("create_re/aha.erb")'' > > Any way to dynamically (hiera) define the templates? > > > Regards > Erkan-- 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/528DE7FA.5090408%40alumni.tu-berlin.de. For more options, visit https://groups.google.com/groups/opt_out.
Ahoi, On Thu, Nov 21, 2013 at 12:01:14PM +0100, Felix Frank wrote:> Hi, > > tough call. You may have to replicate the file type in a defined type > like so: > > define my_file($owner="root",$mode="644",...,$template="") { > > if $template { File[$name] { content => template($template) } } > > file { $name: owner => $owner, ... } > } > > Then you can create_resource(''my_file'',hiera(''input'')) and pass an > actual "template" parameter to your define. >Damn thats look quite a *little* bit more complicated. It evens look some kind of hack. Thats ok with me :) Is there a place to do RTFM about when things are evaluated? At least so I can understand why I need File[$name]? thx Erkan -- 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/1Vk1QZ-0005ta-4u%40linsenraum.de. For more options, visit https://groups.google.com/groups/opt_out.
On Friday, November 22, 2013 6:50:27 PM UTC-6, erkules wrote:> > Ahoi, > > On Thu, Nov 21, 2013 at 12:01:14PM +0100, Felix Frank wrote: > > Hi, > > > > tough call. You may have to replicate the file type in a defined type > > like so: > > > > define my_file($owner="root",$mode="644",...,$template="") { > > > > if $template { File[$name] { content => template($template) } } > > > > file { $name: owner => $owner, ... } > > } > > > > Then you can create_resource(''my_file'',hiera(''input'')) and pass an > > actual "template" parameter to your define. > > > > Damn thats look quite a *little* bit more complicated. > It evens look some kind of hack. Thats ok with me :) > Is there a place to do RTFM about when things are evaluated? > At least so I can understand why I need File[$name]? > >The manual is here: http://docs.puppetlabs.com/puppet/3/reference/. I recommend you at least read the entire "The Puppet Language" section, and that you at least skim the "Resource Types" and "Functions" subsections of the "Generated References" section. As far as the code Felix proposed, it uses a resource parameter override. You can read about that, specifically, here: http://docs.puppetlabs.com/puppet/3/reference/lang_resources.html#amending-attributes-with-a-collector. And yes, resource parameter overrides are somewhat of a hack, though useful at times. In this case, however, I think they are unnecessary. If you are going to add a defined type to hang the behavior on anyway, then why not just make it unconditionally define the content via a template? Then you can achieve the same thing a bit more naturally via a definition such as this one: define mymodule::templated_file( $owner = ''root'', $mode=''0644'', ... <no $content parameter> ... $template) { file { $title: owner => $owner, mode => $mode, # ... content => template($template) } } John -- 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/95eeebb1-38d7-4f4e-a84f-e91287298c17%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.