4

I'm going through a module that manages network, in order to understand how puppet modules work, what I'm stuck on is understanding what $::nisdomainname is, where did it come from and what does "$::" mean and why is the nisdomain portion outside the define block? An excerpt from a file in the module is below, can someone help me with the understanding?

define network::global (
  $hostnamemod = '',
  $gateway = '',
  $vlan = '',
  $nozeroconf = '',
  $gatewaydev = ''
) {
  $nisdomain = $::nisdomainname ? {
    ''      => '',
    default => $::nisdomainname,
  }

Thanks in advance Dan

1 Answer 1

3

In puppet 3.0 and newer, scoping rules will change and you can no longer use $variablename to refer to a variable in global scope, the correct syntax is $::variablename. This syntax also works in 2.7, and maybe in older versions too.

6
  • ahh thanks, but then why wouldn't the other variables like "hostnamemod" also be set as $::hostnamemod = ''?
    – Dan
    Feb 6, 2013 at 13:01
  • Because those are parameters to your define, not references to variables in global scope. Feb 6, 2013 at 13:02
  • ok cleared it up now. Appreciate it.
    – Dan
    Feb 6, 2013 at 13:07
  • One final point, if I may. does the nisdomainname check state, that if the nisdomainname is empty set it to empty otherwise default to setting it to the $::nisdomainname. Which if not defined would be empty, am I right?
    – Dan
    Feb 6, 2013 at 13:07
  • 1
    @DennisKaarsemaker It's not a requirement in 3.0 to specify top scope explicitly. The changes in 3.0 affect dynamic scope only. Feb 7, 2013 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.