Ask Your Question
1

Classify Node from Puppet Agent?

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

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}.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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

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

ramindk gravatar image

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

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.

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

Stats

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

Seen: 75 times

Last updated: Nov 23 '15