dynamically edit node definition

58 views
Skip to first unread message

Sav

unread,
Sep 17, 2011, 11:42:23 AM9/17/11
to puppet...@googlegroups.com
Is it possible to dynamically edit a node definition?  Basically, given a node, add or remove from it's node definition on the fly. 

Right now, I am doing a find on the /etc/puppet/manifests/nodes directory on all ".pp" files, grepping for "node hostname { ", and using a sed command to edit the node definition.  Is there a more straightforward way to do this?  Can it be done in memory?  Or at least, is there a better way to return the .pp file that contains a particular node definition?

Thanks!

Adam Gibbins

unread,
Sep 17, 2011, 10:10:02 PM9/17/11
to puppet...@googlegroups.com

You should probably write an external node classifier (ENC) for this: http://docs.puppetlabs.com/guides/external_nodes.html

Sav

unread,
Sep 17, 2011, 11:28:28 PM9/17/11
to puppet...@googlegroups.com
I looked into that, but I am not in control of all node definitions across the system:

"You can optionally combine an ENC with regular node definitions in site.pp. This works on the “I hope you brought enough for everybody” rule: things will work correctly if you have an ENC and no node definitions, but if there’s at least one node definition, you need to have a default node defined or account for every node with a definition; Puppet will fail compilation with an error if a definition for a given node can’t be found."

In my situation, nodes are already defined, I just need a way to dynamically edit them.  I have no control over the overall puppet config... I simply just need to add to a node definition.  Unless I am misinterpreting, it seems as if ENC could potentially cause conflict with pre-defined nodes.  Am I mistaken on this?

Steve Snodgrass

unread,
Sep 18, 2011, 8:16:03 PM9/18/11
to Puppet Users
Sav,

Maybe I'm confused about what you are trying to do, but why not just
do "import nodes/*" from site.pp instead of using find commands? The
only catch is that if you add or remove a node, you have to do a
"touch" command on site.pp to get puppet to re-read the import
statement and pick up the new (or removed) files.

Sav

unread,
Sep 18, 2011, 9:13:07 PM9/18/11
to puppet...@googlegroups.com
Import nodes/* is already being done.  My problem is, I am not in control of any node definitions.  I am completely ignorant as to what nodes have, or have not been defined (In most situations, the nodes have already been defined).  Given a hostname, I have to (programmatic-ly) find where that node is being defined, and add or remove to the node definition.  If the node has not been defined, I need to create the node definition. 
Message has been deleted

Sav

unread,
Sep 18, 2011, 9:27:46 PM9/18/11
to puppet...@googlegroups.com
To add to my previous post, here is the big picture:

I am given a system, where puppet is already set up.

Lets say a new rpm is created.  I need to install that rpm on a specific host by putting that rpm in a yum repository, and creating a pupmod that installs that rpm on a particular node.  I am writing an application to do this, so it can not be done by hand.  There are other sys-admins that have previously created node definitions for each node... that piece is out of my control.

Here is the pseudo code of what I would ideally like to do:

require 'puppet'

node = Puppet::Node.find_by_name("puppet.example.com")
node.add_to_node_definition("
include \"my yum repo & my rpm\"")

Or is there something within puppet that can *at least* return the file that defines a particular node??
Reply all
Reply to author
Forward
0 new messages