Ask Your Question
0

Puppet agent pull specific class

asked 2016-03-22 08:34:20 -0500

kranthi gravatar image

Hi,

Is there a way, puppet client can retrieve a specific class from the server by running puppet agent command. Please advise

Regards,

Kranthi

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-03-22 14:09:57 -0500

lavaman gravatar image

All the agent can do is request a catalog. The master is the only one that really knows anything about classes or how the code is organized. The master must compile the catalog you wish to apply based on node definitions and/or ENC data. The agent cannot request specific classes.

edit flag offensive delete link more
0

answered 2016-03-26 22:46:35 -0500

DarylW gravatar image

updated 2016-03-26 22:52:13 -0500

It is not directly requesting a single class with a puppet agent call, but we use a setup where our nodes determine what role class they should be applying with a custom fact and a specialized default node.

we have a custom fact that reads the 'role' tag on our AWS Ec2 and uses that to set a tag_role fact.

our default node looks something like this

node default {   
  if defined "roles::${tag_role}" {
    include "roles::${tag_role}"   
  } else {
    notify {"WARN: Unable to apply role::${tag_role}, applying base role instead":}
         include "roles::base"   
  }
}

if for example, tag_role == 'webserver' This allows us to check if the class 'roles::webserver' is on the classpath. If it is, we include that class. If it isn't, we want to apply our base configuration to ensure some basic configuration on our nodes.

This does not allow us to call any arbitrary class directly with an agent call, but it does allow us to not need to hard code each role based on the node-name of the instance we are connecting to.

One thing that I end up doing is creating my own one off box with it's own role that isn't checked into our baseline.. what I can do is arbitrarily include any roles/profiles that I wish to apply in my own node's role, and rerun puppet once my updated role was made available to our master.

If you wanted to set up a special environment for just testing purposes, you would be able to do something similar, and just include the fact as a string directly, e.g. in my example above, before we switched to the roles and profiles pattern, we had one-off modules that acted like a role, and we just included it directly...

if defined $::tag_role {
  include $::tag_role
}

This would allow you to either adjust your fact to match what you wanted to include, or override it with the FACTER_ style env variable

FACTER_tag_role=webserver puppet agent -t
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: 2016-03-22 08:34:20 -0500

Seen: 77 times

Last updated: Mar 26 '16