I have files that have hardcoded IP addresses in them, that are being distributed by puppet. But I want these IPs to be different depending on whether $environment is "production" or something else. With manifests, I can use case statements. Can I do the same somehow with files? johnn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Evan Hisey
2008-Jun-24 17:13 UTC
[Puppet Users] Re: can files make use of case statements?
On Tue, Jun 24, 2008 at 11:45 AM, Johnny Tan <linuxweb@gmail.com> wrote:> > I have files that have hardcoded IP addresses in them, that > are being distributed by puppet. But I want these IPs to be > different depending on whether $environment is "production" > or something else. > > With manifests, I can use case statements. Can I do the same > somehow with files? >This sounds like a good place to use templates. You could use the $environment in teh templates to select which set of ips to use in the files. Evan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Johnny Tan
2008-Jun-24 17:48 UTC
[Puppet Users] Re: can files make use of case statements?
Evan Hisey wrote:> On Tue, Jun 24, 2008 at 11:45 AM, Johnny Tan <linuxweb@gmail.com> wrote: >> I have files that have hardcoded IP addresses in them, that >> are being distributed by puppet. But I want these IPs to be >> different depending on whether $environment is "production" >> or something else. >> >> With manifests, I can use case statements. Can I do the same >> somehow with files? >> > This sounds like a good place to use templates. You could use the > $environment in teh templates to select which set of ips to use in the > files.Just to clarify: You mean, I can use "case" or other selector in the module''s manifest to set the ip variable, which I can then call in the template, right? I don''t actually use "case" within the template itself? johnn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Evan Hisey
2008-Jun-24 18:04 UTC
[Puppet Users] Re: can files make use of case statements?
>> On Tue, Jun 24, 2008 at 11:45 AM, Johnny Tan <linuxweb@gmail.com> wrote: >>> I have files that have hardcoded IP addresses in them, that >>> are being distributed by puppet. But I want these IPs to be >>> different depending on whether $environment is "production" >>> or something else. >>> >>> With manifests, I can use case statements. Can I do the same >>> somehow with files? >>> >> This sounds like a good place to use templates. You could use the >> $environment in teh templates to select which set of ips to use in the >> files. > > Just to clarify: You mean, I can use "case" or other > selector in the module''s manifest to set the ip variable, > which I can then call in the template, right? > > I don''t actually use "case" within the template itself? >you would do teh selecting in the template using a ruby case statement some thing like this the following. This is a stripped down versio nof my printer template using the ruby case statement in a template. <% case hostname when /dhcp/ %> DeviceURI socket://130.160.20.112:9100 <% when /kung-fu/ %> DeviceURI socket://130.160.20.120:9100 <% when /hou120/ %> DeviceURI socket://130.160.35.11:9100 <%end %> Depending on the location you get one of three different ip address fo rthe DeviceURI. Template are ruby erb files and can thus use any ruby syntax. It can just be a bit tricky to figure it out sometimes. Evan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Johnny Tan
2008-Jun-24 18:21 UTC
[Puppet Users] Re: can files make use of case statements?
Evan Hisey wrote:> Depending on the location you get one of three different ip address fo > rthe DeviceURI. Template are ruby erb files and can thus use any ruby > syntax. It can just be a bit tricky to figure it out sometimes.Thanks Evan! That''s exactly what I was looking for! johnn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Shafer
2008-Jun-24 18:53 UTC
[Puppet Users] Re: can files make use of case statements?
Johnn, The templates are not Puppet specific, it is using ERB. You essentially have all the flexibility of Ruby to add logic to the templates. Of course doing too much logic in template can become its own problem. http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/ Cheers, Andrew>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Meier
2008-Jun-25 07:08 UTC
[Puppet Users] Re: can files make use of case statements?
Hi> you would do teh selecting in the template using a ruby case statement > some thing like this the following. This is a stripped down versio nof > my printer template using the ruby case statement in a template. > > <% case hostname > when /dhcp/ %> > DeviceURI socket://130.160.20.112:9100 > <% when /kung-fu/ %> > DeviceURI socket://130.160.20.120:9100 > <% when /hou120/ %> > DeviceURI socket://130.160.35.11:9100 > <%end %> > > Depending on the location you get one of three different ip address fo > rthe DeviceURI. Template are ruby erb files and can thus use any ruby > syntax. It can just be a bit tricky to figure it out sometimes.if you''d like to avoid templates you can also have two static files called file.production and file.development and maybe even a file.default which might be a symling, just do have a default a source for the file which is always working. you can then select these files by: file{''/foobar/ipfile'': source => [ "puppet:///ipfile/file.$environment", "puppet:///ipfile/file.default", ], [....] } doing case without using case statements ;) greets pete --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Johnny Tan
2008-Jun-25 15:22 UTC
[Puppet Users] Re: can files make use of case statements?
Peter Meier wrote:> if you''d like to avoid templates you can also have two static files > called file.production and file.development and maybe even a > file.default which might be a symling, just do have a default a source > for the file which is always working. > > you can then select these files by: > > file{''/foobar/ipfile'': > source => [ "puppet:///ipfile/file.$environment", > "puppet:///ipfile/file.default", ], > [....] > } > > doing case without using case statements ;)Nice. I''m going to use this for most of my selecting. There are a few specific cases where I need the templating, but this works for everything else. Thanks pete. johnn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---