puppetlabs / puppetserver

Server automation framework and application
https://tickets.puppetlabs.com/browse/SERVER
Apache License 2.0
292 stars 235 forks source link

Topscope variable is empty in (sub) modules #2866

Open aloosnetmatch opened 1 month ago

aloosnetmatch commented 1 month ago

Describe the Bug

Topscope variable is empty is (sub) modules / classes, while the same variable IS known in the toplevel 00.pp

We have an 00.pp manifest files that sets a couple of top scope variables. This 00.pp is executed for all agents. We also have other manifests per server who offcourse call other classes.

00.pp

if '<value>' == $::facts.get('<value>') {
  $az_environment = 'prod'
  $test2 = "test2"
}

$test1 = "test1"
notify {"toplevel scope_test1    : ${::test1}" :}
notify {"toplevel scope_test2    : ${::test2}" :}

test.pp

class test {
  notify {"test class scope_test1    : ${::test1}" :}
  notify {"test class scope_test2    : ${::test2}" :}
}

When we apply (and the if statement = "True" ) , we get the results

Notice: toplevel scope_test1    : test1
Notice: toplevel scope_test2    : test2
Notice: test class scope_test1    : 
Notice: test class scope_test2    : test2

Expected Behavior

I expect the top scope variable test1 to always a have the defined value, since it's defined in the top scope. Also remarkable is that when the variable test2 is within the "if" statement , the value works as expected. Moving the variable outside of the "if" statement , makes it "empty" in the sub modules / classes.

Environment

We run puppetserver 7.17.0 and client versions 6.28.0 / 7.31.0.

Additional Context

I noticed this issue:

https://www.puppet.com/docs/puppet/7/known_issues_puppet#pup-11437

In Puppet 6.26 and 7.14, the lookup command fails to resolve toplevel facts in hiera configs if you're using the --environment option

We run a higher version already. (7.17.0)