# Classify Node from Puppet Agent?

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}.dev.co.net$/ { 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? Thanks. edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted The way I've done it in the past looks like this manifests/nodes/default.pp node default { include ::profile::base # wrap in if statement in case role doesn't exist if$::role {
include "${::role}::app::foo::dev" } }  modules/puppet/lib/facter/role.rb require 'facter' Facter.add(:role) do setcode do if File.exist? "/etc/mysystem/role" Facter::Util::Resolution.exec("cat /etc/mysystem/role") end end end  modules/mysystem/templates/role.erb <%= 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 puppet.example.com --environment stage --certname randomname.example.com


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.

more