Hi all, New to puppet and am hoping I can be pointed in the right direction. I have several Amazon EC2 instance in us-east, us-west, eu, and apac. I need different /etc/hosts file for each region. I''m not sure how to implement this in each servers node definition. I''d like to have something like this: node server101 { $location = us-west-1c ... .. } and have it setup the hosts file with the appropriate entries needed from a template. facter has ''ec2_placement_availability_zone'' which has the location info I need. What do I need to read more about to accomplish this in my classes. -- 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.
This sounds like standard file template should work, for that file, use content => template("your-class/your-template.erb"); Then in that file (your-template.erb) you can have: static stuff.... <% if location == "us-west-1c -%> something <% else %> default stuff <% end %> more static stuff The else is optional. Syntax not guaranteed :-) On Tue, Apr 3, 2012 at 2:01 PM, Jim Dehune <jimdehune@gmail.com> wrote:> Hi all, > > New to puppet and am hoping I can be pointed in the right direction. > > I have several Amazon EC2 instance in us-east, us-west, eu, and apac. > I need different /etc/hosts file for each region. I''m not sure how to > implement this in each servers node definition. > > I''d like to have something like this: > > node server101 { > $location = us-west-1c > ... > .. > } > > and have it setup the hosts file with the appropriate entries needed > from a template. facter has ''ec2_placement_availability_zone'' which > has the location info I need. > > What do I need to read more about to accomplish this in my classes. > > -- > 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.
Depending on how complex the hosts file needs to be, what LenR may be best or I have sometimes also approached this kind of issue by using parameterized classes can work well too. You can use a define classname ($variables_to_pass_to_template) { } and then you don''t have to work with ERB-type conditionals. Its a matter of preference in my opinion. So it would do something like this: define location-based-hosts ($my_specific_hosts) { file { "etc/hosts": ensure => present, content => template("puppet:///hosts/hosts_template.erb"), } } Then call it with: hosts::location-based-hosts { "us-west": my_specific_hosts => "list of the important host entries", } And finally, in the hosts_template.erb: 127.0.0.1 localhost <%= my_specific_hosts %> The syntax should be good but I may have missed something. Again its all matter of preference but I have all my templates set up this way, that way my templates look as close to the end file as possible and all the "magic" happens in my manifests.>> >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/-ttLBhVQCiUJ. 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.
We run Foreman, so I never think of parameterized classes :-) Another thing we do in some places is concatenated templates, there is a common section and different appendages. On Wed, Apr 4, 2012 at 8:35 AM, myeazel <matthew.yeazel@gmail.com> wrote:> Depending on how complex the hosts file needs to be, what LenR may be best > or I have sometimes also approached this kind of issue by using > parameterized classes can work well too. You can use a define classname > ($variables_to_pass_to_template) { } and then you don''t have to work with > ERB-type conditionals. Its a matter of preference in my opinion. So it > would do something like this: > > define location-based-hosts ($my_specific_hosts) { > > file { "etc/hosts": > ensure => present, > content => template("puppet:///hosts/hosts_template.erb"), > } > } > > Then call it with: > > hosts::location-based-hosts { "us-west": > my_specific_hosts => "list of the important host entries", > } > > And finally, in the hosts_template.erb: > > 127.0.0.1 localhost > <%= my_specific_hosts %> > > The syntax should be good but I may have missed something. Again its all > matter of preference but I have all my templates set up this way, that way > my templates look as close to the end file as possible and all the "magic" > happens in my manifests. > > >>> >> -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/-ttLBhVQCiUJ. > 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.
jcbollinger
2012-Apr-05 13:19 UTC
[Puppet Users] Re: change host file depending on location
On Apr 4, 8:30 pm, Len Rugen <lenru...@gmail.com> wrote:> We run Foreman, so I never think of parameterized classes :-)My esteem for Foreman has just gone up a notch. :) John -- 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.