homeblogusing rake for puppet enterprise console tasks

Using Rake for Puppet Enterprise Console Tasks

There are all sorts of things you can do in the Puppet Enterprise console, but sometimes, you just don’t want to leave the command line. Fortunately, there’s an extensive rake API that allows you to do pretty much anything you can do from the console, from the command line. This post specifically is about Puppet Enterprise 3.1.2 and higher, but the same tasks can be done, albeit in a different syntax, in older versions as well.

So, let’s say you’ve got a new node, no groups or classifications beyond the default ones that Puppet Enterprise applies. You want to quickly get it into a group, which for this example, we’ll call “chicken.” However, you haven't made the chicken group yet. No problem: You can create a new group with the following: sudo /opt/puppet/bin/rake -f /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production nodegroup:add['chicken’]

So, now we’ve got a group, but there aren’t any classes in it. That’s not going to be much use, so let’s throw in the classes you know all the nodes in the chicken group will need: /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production nodegroup:addclass'chicken','fried'

Great! Say you want to add a few classes to a group at once — you certainly won’t want to type all that out every time. Let’s stack them up:

sudo /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production rake -f nodegroup:addclass['chicken','fried\,boiled\,stewed’]

You could also create the group with the classes right from the start, as well:

sudo /opt/puppet/bin/rake -f /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production nodegroup:add ['chicken','fried\,boiled\,stewed’]

You may notice I’ve added some backslashes into the last two examples. When you’re listing multiple variables, you’ll want to use escaping, detailed more here:


The quick breakdown is, if you have more than one argument between your quote marks, escape before the command and the next argument. Additionally, you can use double quotes, but they require double backslashes:

sudo /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production rake -f nodegroup:addclass[“chicken”,'fried\\,boiled\\,stewed”]

So now we have a group, and the group has some classes. We just need to add nodes to the group. This will add the node spring to the chicken class: sudo /opt/puppet/bin/rake -f /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production node:addgroup ["spring”,”chicken”]

Let's say there are a couple of classes you want to apply to the node that you don’t want the whole group to have. No problem, you can add classes to a node with the following:

sudo /opt/puppet/bin/rake -f /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production node:addclass ["spring”,”fricassee”]

This will add the fricassee class only to the node “spring”.

Additionally, you can stack up rake tasks and run them all at once:

sudo /opt/puppet/share/puppet-dashboard/Rakefile RAILS_ENV=production rake -f nodegroup:add['chicken','fried\,boiled\,stewed’] node:addgroup ["spring”,”chicken”] node:addclass ["spring”,”fricassee”]

This would create the group chicken with the classes fried, boiled, and stewed, add the node spring to group chicken, and add the class fricassee to the node spring. Chances are you won’t want or need to stack up something quite like this, but it’s an example of the way you can stack multiple kinds of Rake tasks.

For more tasks and extended information, including adding things like class parameters, you can see the full list here: http://docs.puppetlabs.com/pe/latest/console_rake_api.html

Puppet sites use proprietary and third-party cookies. By using our sites, you agree to our cookie policy.