0

I have the following puppet setup (pretty simple):

/etc/puppet/manifests/site.pp:

node 'node.my.domain' {
  $nodeclass = 1
  notify { "(INFO) nodeclass = $nodeclass": }

  class { "foobar": }
}

/etc/puppet/modules/foobar/manifests/site.pp:

class foobar {
  notify { "(INFO) in foobar: nodeclass = nodeclass": }
}

On node.my.domain, I run:

node# puppet agent -t

I receive the following output:

Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for node.my.domain
Info: Applying configuration version '1496349702'
Notice: (INFO) nodeclass =
Notice: /Stage[main]/Foobar/Notify[(INFO) in foobar: nodeclass = ]/message: defined 'message' as '(INFO) in foobar: nodeclass = '
Notice: Finished catalog run in 0.50 seconds

i.e. $nodeclass is empty. How do I properly access a node-scope variable from within a class?

J. Graham
  • 1
  • 1

1 Answers1

0

Scope-level inheritance is outdated and should be replaced with class parameters. Also, your directory structure is wrong.

/etc/puppetlabs/code/manifests/site.pp

node 'node.my.domain' {
  $nodeclass = 1
  notify { "(INFO) nodeclass = ${nodeclass}": }

  class { "foobar":
    nodeclass => $nodeclass,
  }
}

/etc/puppetlabs/code/modules/foobar/manifests/init.pp

class foobar(
  $nodeclass,
){
  notify { "(INFO) in foobar: nodeclass = ${nodeclass}": }
}
Craig Watson
  • 9,575
  • 3
  • 32
  • 47