I have the following puppet setup (pretty simple):


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

  class { "foobar": }


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?

1 Answer 1


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


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

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


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

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.