Sorry if this has been asked, but Google has failed me and I haven''t been able to find an answer. With a source one can declare array so that if file exist puppet will pull it out first, if not move to the next file in this fashion: source => ["puppet:///conf/httpd_$hostname.conf", "puppet:///conf/httpd.conf", ], To the best of my knowledge one can''t do that with a Template (at least as of 0.24, I am hoping this has changed). What is the recommended way of dealing with this? I do know that I can have an "if" statement within a class/module to go like this: if $hostname { content =... However that isn''t as clean as being able to do this from within the same array as "source". That way instead of keep having to add "if/else" I can simply add a file as needed. Thank you! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hey Marek, Templates do have different functionality here - they will concatenate arrays of templates (i.e. if you pass more than one template, it concatenates them all together into one file). You might want to check out the blog on separating data from code ( http://puppetlabs.com/blog/the-problem-with-separating-data-from-puppet-code/) to see ways that you can specify that piece of data entirely separate from your puppet code. On Thu, Apr 12, 2012 at 9:42 AM, Marek Dohojda <chrobry@gmail.com> wrote:> Sorry if this has been asked, but Google has failed me and I haven''t been > able to find an answer. > > With a source one can declare array so that if file exist puppet will pull > it out first, if not move to the next file in this fashion: > > source => ["puppet:///conf/httpd_$hostname.conf", > "puppet:///conf/httpd.conf", > ], > > To the best of my knowledge one can''t do that with a Template (at least as of 0.24, I am hoping this has changed). > > What is the recommended way of dealing with this? > > I do know that I can have an "if" statement within a class/module to go like this: > > if $hostname { > content =... > > However that isn''t as clean as being able to do this from within the same array as "source". That way instead of keep having to add "if/else" I can simply add a file as needed. > > Thank you! > > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- Gary Larizza Professional Services Engineer Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hello Thank you Unfortunately this won''t help me at the moment because the files are different completely and not just few parameters. I need different templates based on hostname. I am fully aware that I can use "if" but well..ahm.. its ugly :) On Thu, Apr 12, 2012 at 10:53 AM, Gary Larizza <gary@puppetlabs.com> wrote:> Hey Marek, > > Templates do have different functionality here - they will concatenate > arrays of templates (i.e. if you pass more than one template, it > concatenates them all together into one file). You might want to check out > the blog on separating data from code ( > http://puppetlabs.com/blog/the-problem-with-separating-data-from-puppet-code/) > to see ways that you can specify that piece of data entirely separate from > your puppet code. > > > > On Thu, Apr 12, 2012 at 9:42 AM, Marek Dohojda <chrobry@gmail.com> wrote: > >> Sorry if this has been asked, but Google has failed me and I haven''t been >> able to find an answer. >> >> With a source one can declare array so that if file exist puppet will >> pull it out first, if not move to the next file in this fashion: >> >> source => ["puppet:///conf/httpd_$hostname.conf", >> "puppet:///conf/httpd.conf", >> ], >> >> To the best of my knowledge one can''t do that with a Template (at least as of 0.24, I am hoping this has changed). >> >> What is the recommended way of dealing with this? >> >> I do know that I can have an "if" statement within a class/module to go like this: >> >> >> if $hostname { >> content =... >> >> However that isn''t as clean as being able to do this from within the same array as "source". That way instead of keep having to add "if/else" I can simply add a file as needed. >> >> >> Thank you! >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Puppet Users" group. >> To post to this group, send email to puppet-users@googlegroups.com. >> To unsubscribe from this group, send email to >> puppet-users+unsubscribe@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/puppet-users?hl=en. >> > > > > -- > > Gary Larizza > Professional Services Engineer > Puppet Labs > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Thu, Apr 12, 2012 at 11:39 AM, Marek Dohojda <chrobry@gmail.com> wrote:> Hello > > Thank you > Unfortunately this won''t help me at the moment because the files are > different completely and not just few parameters. I need different > templates based on hostname. > I am fully aware that I can use "if" but well..ahm.. its ugly :) > >Right, If you used something like Hiera you could do a lookup on a variable (like $foo_content for example) and hiera would pass a different value for the content attribute based on the hostname of the machine. So if it were one hostname you could get something like "template(''module/first_template.erb'')" and another hostname would return a value of "template(''module/second_template.erb'')". Then, in the declaration, you could do: file { ''/path/to/file'': ensure => present, content => $foo_content, } Your Puppet code would be generic (only using a variable) and all your data would be determined in Hiera. If you''re interested in this method, there''s also a blog post for using Hiera here --> http://puppetlabs.com/blog/first-look-installing-and-using-hiera/> > > > On Thu, Apr 12, 2012 at 10:53 AM, Gary Larizza <gary@puppetlabs.com>wrote: > >> Hey Marek, >> >> Templates do have different functionality here - they will concatenate >> arrays of templates (i.e. if you pass more than one template, it >> concatenates them all together into one file). You might want to check out >> the blog on separating data from code ( >> http://puppetlabs.com/blog/the-problem-with-separating-data-from-puppet-code/) >> to see ways that you can specify that piece of data entirely separate from >> your puppet code. >> >> >> >> On Thu, Apr 12, 2012 at 9:42 AM, Marek Dohojda <chrobry@gmail.com> wrote: >> >>> Sorry if this has been asked, but Google has failed me and I haven''t >>> been able to find an answer. >>> >>> With a source one can declare array so that if file exist puppet will >>> pull it out first, if not move to the next file in this fashion: >>> >>> source => ["puppet:///conf/httpd_$hostname.conf", >>> "puppet:///conf/httpd.conf", >>> ], >>> >>> To the best of my knowledge one can''t do that with a Template (at least as of 0.24, I am hoping this has changed). >>> >>> What is the recommended way of dealing with this? >>> >>> I do know that I can have an "if" statement within a class/module to go like this: >>> >>> >>> >>> if $hostname { >>> content =... >>> >>> However that isn''t as clean as being able to do this from within the same array as "source". That way instead of keep having to add "if/else" I can simply add a file as needed. >>> >>> >>> >>> Thank you! >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Puppet Users" group. >>> To post to this group, send email to puppet-users@googlegroups.com. >>> To unsubscribe from this group, send email to >>> puppet-users+unsubscribe@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/puppet-users?hl=en. >>> >> >> >> >> -- >> >> Gary Larizza >> Professional Services Engineer >> Puppet Labs >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Puppet Users" group. >> To post to this group, send email to puppet-users@googlegroups.com. >> To unsubscribe from this group, send email to >> puppet-users+unsubscribe@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/puppet-users?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- Gary Larizza Professional Services Engineer Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Marek, I''d suggest using something like the following to use a template based on hostname: file { ''/path/to/file'': template => $hostname ? { /regex/ => ''puppet://module/template.erb'', /regex2/ => ''puppet://module/template1.erb'', default => ''puppet://module/default-template.erb'', } } This is a more elegant solution than a bunch of if statements, well this is essentially an if statement as well, just prettier. On 4/12/12 2:39 PM, Marek Dohojda wrote:> Hello > > Thank you > Unfortunately this won''t help me at the moment because the files are > different completely and not just few parameters. I need different > templates based on hostname. > I am fully aware that I can use "if" but well..ahm.. its ugly :) > > > > On Thu, Apr 12, 2012 at 10:53 AM, Gary Larizza <gary@puppetlabs.com > <mailto:gary@puppetlabs.com>> wrote: > > Hey Marek, > > Templates do have different functionality here - they will > concatenate arrays of templates (i.e. if you pass more than one > template, it concatenates them all together into one file). You > might want to check out the blog on separating data from code > (http://puppetlabs.com/blog/the-problem-with-separating-data-from-puppet-code/) > to see ways that you can specify that piece of data entirely > separate from your puppet code. > > > > On Thu, Apr 12, 2012 at 9:42 AM, Marek Dohojda <chrobry@gmail.com > <mailto:chrobry@gmail.com>> wrote: > > Sorry if this has been asked, but Google has failed me and I > haven''t been able to find an answer. > > With a source one can declare array so that if file exist > puppet will pull it out first, if not move to the next file in > this fashion: > > source => ["puppet:///conf/httpd_$hostname.conf", > "puppet:///conf/httpd.conf", > ], > > To the best of my knowledge one can''t do that with a Template (at least as of 0.24, I am hoping this has changed). > > What is the recommended way of dealing with this? > > I do know that I can have an "if" statement within a class/module to go like this: > > > > > if $hostname { > content =... > > However that isn''t as clean as being able to do this from within the same array as "source". That way instead of keep having to add "if/else" I can simply add a file as needed. > > > > > Thank you! > > > -- > You received this message because you are subscribed to the > Google Groups "Puppet Users" group. > To post to this group, send email to > puppet-users@googlegroups.com > <mailto:puppet-users@googlegroups.com>. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com > <mailto:puppet-users%2Bunsubscribe@googlegroups.com>. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > > > > -- > > Gary Larizza > Professional Services Engineer > Puppet Labs > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com > <mailto:puppet-users@googlegroups.com>. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com > <mailto:puppet-users%2Bunsubscribe@googlegroups.com>. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- Steve King Network/Linux Engineer - AdSafe Media Cisco Certified Network Professional CompTIA Linux+ Certified Professional CompTIA A+ Certified Professional -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hey that does look heck of a lot prettier! Thanks! On Thu, Apr 12, 2012 at 1:02 PM, Steven King <sking@kingrst.com> wrote:> Marek, > > I''d suggest using something like the following to use a template based on > hostname: > > file { ''/path/to/file'': > template => $hostname ? { > /regex/ => ''puppet://module/template.erb'', > /regex2/ => ''puppet://module/template1.erb'', > default => ''puppet://module/default-template.erb'', > } > } > > This is a more elegant solution than a bunch of if statements, well this > is essentially an if statement as well, just prettier. > > > On 4/12/12 2:39 PM, Marek Dohojda wrote: > > Hello > > Thank you > Unfortunately this won''t help me at the moment because the files are > different completely and not just few parameters. I need different > templates based on hostname. > I am fully aware that I can use "if" but well..ahm.. its ugly :) > > > > On Thu, Apr 12, 2012 at 10:53 AM, Gary Larizza <gary@puppetlabs.com>wrote: > >> Hey Marek, >> >> Templates do have different functionality here - they will concatenate >> arrays of templates (i.e. if you pass more than one template, it >> concatenates them all together into one file). You might want to check out >> the blog on separating data from code ( >> http://puppetlabs.com/blog/the-problem-with-separating-data-from-puppet-code/) >> to see ways that you can specify that piece of data entirely separate from >> your puppet code. >> >> >> >> On Thu, Apr 12, 2012 at 9:42 AM, Marek Dohojda <chrobry@gmail.com>wrote: >> >>> Sorry if this has been asked, but Google has failed me and I haven''t >>> been able to find an answer. >>> >>> With a source one can declare array so that if file exist puppet will >>> pull it out first, if not move to the next file in this fashion: >>> >>> source => ["puppet:///conf/httpd_$hostname.conf", >>> "puppet:///conf/httpd.conf", >>> ], >>> >>> To the best of my knowledge one can''t do that with a Template (at least as of 0.24, I am hoping this has changed). >>> >>> What is the recommended way of dealing with this? >>> >>> I do know that I can have an "if" statement within a class/module to go like this: >>> >>> >>> >>> >>> if $hostname { >>> content =... >>> >>> However that isn''t as clean as being able to do this from within the same array as "source". That way instead of keep having to add "if/else" I can simply add a file as needed. >>> >>> >>> >>> >>> Thank you! >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Puppet Users" group. >>> To post to this group, send email to puppet-users@googlegroups.com. >>> To unsubscribe from this group, send email to >>> puppet-users+unsubscribe@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/puppet-users?hl=en. >>> >> >> >> >> -- >> >> Gary Larizza >> Professional Services Engineer >> Puppet Labs >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Puppet Users" group. >> To post to this group, send email to puppet-users@googlegroups.com. >> To unsubscribe from this group, send email to >> puppet-users+unsubscribe@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/puppet-users?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > > -- > Steve King > > Network/Linux Engineer - AdSafe Media > Cisco Certified Network Professional > CompTIA Linux+ Certified Professional > CompTIA A+ Certified Professional > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.