Grouping nodes in puppet

puppet

In my site.pp manifest, I have the following

import "nodes/*.pp"

This lets me nicely create separate files for different groups. However, inside each .pp file, i still have to explicitly set the name of the nodes I want to apply modules and classes to, as so:

node puppet-client-1 {
  include testmodule
}

My question is, How do I group a number of nodes together, and then apply modules and/or classes to that node group? eg:

group testgroup{
  puppet-client1
  puppet-client2
}

node webservers
{
  include testmodule
}

While I am here, my log is spitting out this:

The use of 'import' is deprecated at /etc/puppet/manifests/site.pp:2

If this is deprecated, how do I split out my manifest files into groups?

Thanks 🙂

Best Answer

There's two ways:

1) Multiple node names in one line:

node 'puppet-client1', 'puppet-client2' {
    include testmodule
}

2) Nodes can be defined with regexes, e.g.:

node /^puppet-client[0-9]+/{
  include testmodule
}

but that depends on a suitable host naming scheme.

You can see the official documentation for node definitions.