Ask Your Question

How to refer to common variables across multiple modules

asked 2013-05-02 05:00:26 -0600

maxwell gravatar image

updated 2013-05-02 09:03:31 -0600

We need to refer to common variables across multiple modules. For example, our dns module, firewall module and monitoring module need knowledge of our radius server IP address. Is the correct approach to create a 'common' class where these variables are defined and then reference them from each module and create a class dependancy as below. We are using a custom ENC which outputs the class parameters.

# modules/common/manifest/init.pp
class common (
) {

# modules/common/manifest/apache.pp
class apache (
  $fw_ip = $common::fw_ip,
  $zabbix_ip =$common::zabbix_ip,
) {
  class { 'common': } ->
  class { 'apache': }

# modules/common/manifest/maradns.pp
class ...
edit retag flag offensive close merge delete


This will work though I suggest fully qualifying your variables rooted in the root name space. So instead of $common::fw_ip use $::common::fw_ip and class { '::apache' }. This will avoid ...(more)

Daenney gravatar imageDaenney ( 2013-05-05 04:33:06 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-05-02 08:23:00 -0600

chsnell gravatar image

If it's data, you want to look into hiera. Just stick the radius server's IP into a yaml file in your hiera data directory and then use the hiera function in each of your modules to return that value. Instead of your $radius_ip = $common::radius_ip line, you would have something like this:

$radius_ip = hiera('radius_ip')

edit flag offensive delete link more


Thanks but we have moved from Hiera to a custom ENC solution.

maxwell gravatar imagemaxwell ( 2013-05-02 08:49:19 -0600 )edit

Then yes, what you have listed in your code should work (sorry, missed the ENC section), and it's what I'd probably do.

chsnell gravatar imagechsnell ( 2013-05-02 08:56:04 -0600 )edit

Out of curiosity, have you thought about building a simple backend for hiera that queries your custom ENC parameters?

Ancillas gravatar imageAncillas ( 2013-05-02 10:54:56 -0600 )edit

@Ancillas No, and I'm not sure what the purpose of that would be.

maxwell gravatar imagemaxwell ( 2013-05-02 11:12:42 -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


Asked: 2013-05-02 05:00:26 -0600

Seen: 718 times

Last updated: May 02 '13