Ask Your Question

Classify Node from Puppet Agent?

asked 2015-11-21 16:37:46 -0600

dmourati gravatar image

I'd like to run puppet agent on a new node and classify that node from the client.

We use a roles/profiles approach that currently matches based on hostname.

Dev Environment node

/^foo\d{2}$/ {
include ::role::app::foo::dev }

In my new environment, I'll be creating ephemeral VMs and their names will not encode any information about their roles. Rather, I'd like to do something like:

puppet agent --test --role app::foo::dev

We use puppet 3.6.

How can I do that?


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-11-22 13:20:33 -0600

ramindk gravatar image

updated 2015-11-23 11:54:15 -0600

The way I've done it in the past looks like this


node default {
  include ::profile::base

  # wrap in if statement in case role doesn't exist
  if $::role {
    include "${::role}::app::foo::dev"


require 'facter'

Facter.add(:role) do
  setcode do
    if File.exist? "/etc/mysystem/role"
      Facter::Util::Resolution.exec("cat /etc/mysystem/role")


<%= scope['::role'] %>

We use a role fact that is undefined unless you edit the file or pass it on the commandline. We always apply base so at least we can ssh into the machine if something goes wrong. We pass $role on the command line when we provision the machines.

sudo FACTER_role=myrole puppet agent --server --environment stage --certname

We built this before /etc/facter/facts.d/ was introduced. I'd use that dir structure instead of writing a custom fact and rely on facter to read /etc/facter/facts.d/role which should be in the form of k=v. You will still need a way for Puppet to store the fact, I'd use the template example, once it receives from the command line.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-11-21 16:32:55 -0600

Seen: 103 times

Last updated: Nov 23 '15