Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to refer to common variables across multiple modules

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 (
  $radius_ip, 
  $fw_ip,
  $zabbix_ip,
) {
}

# 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 maradns (
  $radius_ip = $common::radius_ip,
  $fw_ip = $common::vpn_ip,
){
  class { 'maradns': } ->
  class { 'apache': }
}

# ENC ouput
---
classes:
    common:
      fw_ip: '10.50.1.1'
      radius_ip: '10.50.1.12'
      zabbix_ip: '10.50.1.11'
    apache:
    ntp:
    maradns:
environment: production

How to refer to common variables across multiple modules

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 (
  $radius_ip, 
  $fw_ip,
  $zabbix_ip,
) {
}

# 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 maradns (
  $radius_ip = $common::radius_ip,
  $fw_ip = $common::vpn_ip,
){
  class { 'maradns': 'common': } ->
  class { 'apache': }
}

# ENC ouput
---
classes:
    common:
      fw_ip: '10.50.1.1'
      radius_ip: '10.50.1.12'
      zabbix_ip: '10.50.1.11'
    apache:
    ntp:
    maradns:
environment: production