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:
- 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
- In the appropriate manifest, set the class parameters according to those node facts. You can do that conditionally, if you prefer.
- Run the agent normally. If you wish, you can use the --tag option to limit the resources to be applied.