passing parameters

433 views
Skip to first unread message

Michael Hüttermann

unread,
Dec 19, 2012, 4:45:39 PM12/19/12
to puppet...@googlegroups.com
Hello,

I use a parameterized class and declare it as a resource. How can I pass
the parameters from outside any declaration or manifest, during runtime?
For example, can I pass the parameters during a call of "puppet kick" ?


Thank you.


Best regards
Michael

Peter Brown

unread,
Dec 19, 2012, 6:47:27 PM12/19/12
to puppet-users
Have a look here.
I am assuming you are running puppet 3 but the syntax is the same in 2.6 and 2.7.
http://docs.puppetlabs.com/puppet/3/reference/lang_classes.html#using-resource-like-declarations




Michael

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.


jcbollinger

unread,
Dec 20, 2012, 9:32:48 AM12/20/12
to puppet...@googlegroups.com


On Wednesday, December 19, 2012 3:45:39 PM UTC-6, Michael Hüttermann wrote:

I use a parameterized class and declare it as a resource. How can I pass
the parameters from outside any declaration or manifest, during runtime?


To the best of my knowledge, it is not possible to do such a thing, at least not directly (but see below).

Puppet always operates by compiling a manifest set into a catalog containing a digested version of all the resources, parameters, properties, and relationships to apply, and then applying the compiled catalog without considering further input.  Those two steps often occur on different systems (master / agent) but they can be done all in one process ("puppet apply").  Class parameter values are determined strictly during manifest compilation.

What you are asking for seems directed toward using Puppet as a script engine, and that's very much counter to Puppet's architecture and intended problem space.  Puppet's objective is to establish and maintain known configurations on target nodes, so it really doesn't make sense to have it determine the appropriate parameters on a per-run basis.  If that's what you want then I'd recommend you write an ordinary script.

Nevertheless, if you insist on doing as you say, then here's a way to accomplish it:
  1. Set environment-based node facts for the desired parameter values, as described here: http://docs.puppetlabs.com/guides/faq.html#can-i-access-environment-variables-with-facter
  2. In the appropriate manifest, set the class parameters according to those node facts.  You can do that conditionally, if you prefer.
  3. Run the agent normally.  If you wish, you can use the --tag option to limit the resources to be applied.

For example, can I pass the parameters during a call of "puppet kick" ?



"puppet kick" just triggers the agent (if it's listening) to perform an ordinary catalog run.


John

jcbollinger

unread,
Jan 9, 2013, 10:46:48 AM1/9/13
to puppet...@googlegroups.com


On Tuesday, January 8, 2013 4:15:02 AM UTC-6, Michael Hüttermann wrote:
Hello,
I don't get that example working. Looks like the variable is not set although "facter" lists it. In my manifest, I can access all Facter variables, but not the one I've defined the way described in your post and in the FAQ. It's empty. I'm on Puppet 2.7. What can be the reason?


It's hard to say without looking at your code and command(s), but my first guess would be that the variables in question are not set in the environment in which the Puppet agent is running.  This is a function of how the agent is started.  In particular, do not assume that the agent will have the environment of a login shell unless you start it from one.


John

Reply all
Reply to author
Forward
0 new messages