Hi all, I''m new to puppet put did a lot with cfengine2 at my last gig. I''m using v0.25.4 (default) on Ubuntu Lucid but can upgrade to 2.6 if necessary. I have a few hundred (with more on the way) machines in a new datacenter. I have about a dozen classes of hosts, designated by <dc>-<function><n>, so for example: sjc-web29 sjc-db35 sjc-smtp3 My nodes.pp is super-simple this way: node default { include dsh include getty include grub include ntp include postfix include ssh include sudo } This worked really well in cfengine, allowing me to keep decisions self-contained within individual modules. I''m trying to do the same with puppet without any luck so far. Ideally I''d do something like: $role = inline_template("<%= %x{/bin/hostname | /bin/sed -re ''s/.*\-(\w+)[0-9]/\1/g''} %>") tag("type_${role}") And then do if tagged("role_smtp") within the modules. This keeps my high level simple in that I just call modules and they do the right thing. The problem is this doesn''t seem to work. It seems that $role and the tags never get set, even if I try to set them manually so I''m clearly doing something fundamentally wrong. Has anyone done this type of setup where all the decisions are made within the modules themselves based on parts of a hostname or tags? I''m happy to provide more information or post more bits of my config if needed. Thanks! Joe -- 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.
I think I solved my own problem. Now things look like this. I can still do specific node overrides, but this seems to do what I''m hoping for. If there''s a better way to do this sort of thing I''m happy to be corrected. class general { include dsh include getty include grub include ntp include postfix include ssh include sudo include sysadmin } node default { $role = inline_template(''<%= hostname.sub(/\w+-([a-z]+)\d*/){$1} %>'') include general } On Mon, Feb 7, 2011 at 4:46 PM, Joe Gross <jgross@stimpy.net> wrote:> Hi all, > > I''m new to puppet put did a lot with cfengine2 at my last gig. I''m using > v0.25.4 (default) on Ubuntu Lucid but can upgrade to 2.6 if necessary. > > I have a few hundred (with more on the way) machines in a new datacenter. I > have about a dozen classes of hosts, designated by <dc>-<function><n>, so > for example: > > sjc-web29 > sjc-db35 > sjc-smtp3 > > My nodes.pp is super-simple this way: > > node default { > include dsh > include getty > include grub > include ntp > include postfix > include ssh > include sudo > } > > This worked really well in cfengine, allowing me to keep decisions > self-contained within individual modules. I''m trying to do the same with > puppet without any luck so far. Ideally I''d do something like: > > $role = inline_template("<%= %x{/bin/hostname | /bin/sed -re > ''s/.*\-(\w+)[0-9]/\1/g''} %>") > tag("type_${role}") > > And then do if tagged("role_smtp") within the modules. This keeps my high > level simple in that I just call modules and they do the right thing. > > The problem is this doesn''t seem to work. It seems that $role and the tags > never get set, even if I try to set them manually so I''m clearly doing > something fundamentally wrong. > > Has anyone done this type of setup where all the decisions are made within > the modules themselves based on parts of a hostname or tags? I''m happy to > provide more information or post more bits of my config if needed. > > Thanks! > > Joe > >-- 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.
Felix Frank
2011-Feb-09 07:41 UTC
Re: [Puppet Users] Re: host classification based on hostnames
On 02/08/2011 07:59 AM, Joe Gross wrote:> I think I solved my own problem. Now things look like this. I can still > do specific node overrides, but this seems to do what I''m hoping for. > > If there''s a better way to do this sort of thing I''m happy to be corrected. > > class general { > include dsh > include getty > include grub > include ntp > include postfix > include ssh > include sudo > include sysadmin > } > > node default { > $role = inline_template(''<%= hostname.sub(/\w+-([a-z]+)\d*/){$1} %>'') > include general > }Hi. Yes, this is currently possible and (I believe) quite common. While I appreciate your cfengine background, this way of thinking may well get you stuck rubbing puppet wrong forever, though. Puppet leans (IMO) more strongly towards a loose architecture, making decisions at mixed granularities, such as if $virtual == "physical" { include ssh } at some central place in your manifests, and making more such choices *inside* the ssh class as well. You may even want to replace your role semantics by a collection of custom facts you install on all your boxes that will explain puppet what to do. Just my 2c Felix -- 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.
Nigel Kersten
2011-Feb-09 09:06 UTC
Re: [Puppet Users] host classification based on hostnames
On Mon, Feb 7, 2011 at 11:46 PM, Joe Gross <jgross@stimpy.net> wrote:> Hi all, > > I''m new to puppet put did a lot with cfengine2 at my last gig. I''m using > v0.25.4 (default) on Ubuntu Lucid but can upgrade to 2.6 if necessary. > > I have a few hundred (with more on the way) machines in a new datacenter. I > have about a dozen classes of hosts, designated by <dc>-<function><n>, so > for example: > > sjc-web29 > sjc-db35 > sjc-smtp3 > > My nodes.pp is super-simple this way: > > node default { > include dsh > include getty > include grub > include ntp > include postfix > include ssh > include sudo > } > > This worked really well in cfengine, allowing me to keep decisions > self-contained within individual modules. I''m trying to do the same with > puppet without any luck so far. Ideally I''d do something like: > > $role = inline_template("<%= %x{/bin/hostname | /bin/sed -re > ''s/.*\-(\w+)[0-9]/\1/g''} %>") > tag("type_${role}")You realize this will execute on the master, and thus use the master hostname rather than the node?> > And then do if tagged("role_smtp") within the modules. This keeps my high > level simple in that I just call modules and they do the right thing. > > The problem is this doesn''t seem to work. It seems that $role and the tags > never get set, even if I try to set them manually so I''m clearly doing > something fundamentally wrong. > > Has anyone done this type of setup where all the decisions are made within > the modules themselves based on parts of a hostname or tags? I''m happy to > provide more information or post more bits of my config if needed.This is actually my favorite way of doing things. A single default node that includes a single module "base" which then decides which other modules to include. This does work best if you distribute custom facts that provide more abstracted semantics about roles though. Otherwise you end up with spaghetti Puppet code like you''ve started with above :) Say you distribute a custom fact "role", it then becomes as simple as: class base { if $role == "foo" { include foo } } Or if you absolutely know you have a one to one mapping between modules and roles, just "include $foo", but in my experience you usually want a little more logic involved than that.> > Thanks! > > Joe > > -- > 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 Wed, Feb 9, 2011 at 3:06 AM, Nigel Kersten <nigel@puppetlabs.com> wrote:> > > This is actually my favorite way of doing things. A single default > node that includes a single module "base" which then decides which > other modules to include. > > This does work best if you distribute custom facts that provide more > abstracted semantics about roles though. Otherwise you end up with > spaghetti Puppet code like you''ve started with above :) > > Say you distribute a custom fact "role", it then becomes as simple as: > > class base { > > if $role == "foo" { include foo } > > } > >This is really helpful. It allows extra flexibility and still keeps things compartmentalized. Thanks, Joe -- 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.