Ask Your Question

When do I use parameterized classes?

asked 2013-03-25 16:06:56 -0600

nathanlong85 gravatar image

updated 2013-04-01 08:11:58 -0600

Stefan gravatar image

I have a few variables that will be different depending on the node definition and I'm not sure where/how to declare them.

As an example, which is the best way to pass variables to a class?

node default {
    $ntp_primary = ''
    $ntp_secondary = ''
    include ntp


node default {
    class { ntp:
        ntp_primary => '',
        ntp_secondary => ''

The first way I'd just reference the variable inside of the ntp class. The second way I'm using a parameterized class and passing the variables to it.

From what I've ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2013-03-26 09:45:40 -0600

Ancillas gravatar image

updated 2013-03-27 00:09:22 -0600

In Puppet 3.0+, the scope of variables becomes more important than in previous versions of Puppet. Since it is likely that the same variable names will be used in several modules, it's important that the scope of variables be limited.

Before looking at your case, it's important to understand the difference between using "include" to add a module to the catalog versus using "class".

"include" allows for the same module or class to be called multiple times. If the module or class is already in the catalog, then Puppet will simply use that already existing instance. However ... (more)

edit flag offensive delete link more


So since I'm using puppet 3 on all of my nodes, I should just be using includes with data bindings in my node definitions? Would you be able to ...(more)

nathanlong85 gravatar imagenathanlong85 ( 2013-03-26 10:55:29 -0600 )edit

Were you able to find answers for all of your questions?

Ancillas gravatar imageAncillas ( 2013-03-28 15:29:15 -0600 )edit

Yeah, I think so for now. Thank's so much for your help, I really appreciate it!

nathanlong85 gravatar imagenathanlong85 ( 2013-03-28 16:26:31 -0600 )edit

Excellent. If you have a moment, please accept my answer so that the question will be marked as solved for future people looking for help. Thanks!

Ancillas gravatar imageAncillas ( 2013-04-01 15:05:59 -0600 )edit

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


Asked: 2013-03-25 16:06:56 -0600

Seen: 218 times

Last updated: Mar 27 '13