Globally used parameter

20 views
Skip to first unread message

Marco Dürrwächter

unread,
Sep 19, 2014, 4:09:35 AM9/19/14
to puppet...@googlegroups.com
Hi,

I'm searching for the best way to use parameter in multiple modules.

Example: I am declaring a variable $port in module 'server' and I need this variable in module 'firewall' to open this port. If i have to change this variable I actually have to change 4 Variables in 4 modules.

Is there a way to load variables from a property file, or an extra 'settings' module?
What would be the best solution?

Greets,
Marco

José Luis Ledesma

unread,
Sep 19, 2014, 3:25:34 PM9/19/14
to puppet...@googlegroups.com

Using hiera is probably the best solution.

Regards,

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e38822b8-bd6a-4156-800f-ac9592f8b950%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
Sep 22, 2014, 11:16:05 AM9/22/14
to puppet...@googlegroups.com


On Friday, September 19, 2014 2:25:34 PM UTC-5, Jose Luis Ledesma wrote:

Using hiera is probably the best solution.


So that would mean creating 'server' as an hiera item, and having each class that wanted it look it up as

    $server = hiera('server')

That's basically the property file approach.  An alternative would be to choose one class to be the owner of the data, and have all the other classes involved use that.  The chosen class could be one of the existing ones, or it could be a separate one, possibly in a different module:

class settings::network {
  $port = 1234
}

class server::config {
  $listen_port = $::settings::network::port
}

Do understand, however, that cross-module variable references are considered poor form by many, as they undermine modularity.  Inter-class variable references are better limited to classes in the same module.


John

Reply all
Reply to author
Forward
0 new messages