Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy way to return the top level classes applied to a node. By this I mean the classes included in a node definition or ENC equivalent For example with the sample node below, I'd like to return 'return::me' and 'return::me2' for somehost, but not 'dontreturn::me'

class return::me {
   include dontreturn::me
node "somehost" {
   include return::me
   include return::me2

I see that /var/lib/puppet/state/classes.txt includes the full list of classes applied to the node, but that includes any additional classes included by to the top level classes.

Is there some way to get at this data with a puppet faces command ? I suspect 'puppet nodes' might be useful, but I haven't been able to get it return what I what.

share|improve this question
file { '/var/lib/puppet/state/classes.txt':
  content => inline_template("<%= Puppet::Node.indirection.find(fqdn).classes.join('\n') + '\n' %>"),

Works at least with recent 2.6.x and with 2.7.x (haven't tried earlier versions).

Given this uses internal Puppet APIs, I can't make any guarantees about this trick's longevity. Unfortunately there's nothing better anyway.

We used to have a puppet 2.6 trick using Puppet::Node.find(fqdn).classes instead, but it broke with 2.7.

share|improve this answer
This didn't work for me, but I upvoted it anyway since I wouldn't have thought of this approach. I'm looking for something that works on the command line, and the little one-liner below was returning an empty list for the classes. ruby -e "require 'puppet'; print Puppet::Node.indirection.find('myhost').classes.join('\n') + '\n'" – pwan Jul 6 '12 at 18:31
You can't have a command running on the client giving you the information, as the external node classifier and manifests are only known by the puppetmaster and never exposed to the puppet agent (only the compiled manifests are). So you'll need a trick like mine in your manifests, which is compiled by the puppetmaster then provided to the agent. – Pierre Carrier Jul 7 '12 at 1:01

I eventually got 'puppet node' to work. The command below is working when run on the 'myhost' machine. It looks like this works for nodes defined with a 'node' block as well as definitions coming in from the ENC.

puppet node find 'myhost' --render-as yaml --terminus rest | grep " - "
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.