puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide

Home Page:https://puppetlabs.github.io/puppet-lint/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Top scope variable are rewritten into fact references

brunoleon opened this issue · comments

Describe the Bug

The PR #190 introduces a bug that prevent reference to top scope variables by rewriting into a reference to a fact

$::example_var => save => $facts['example_var']

Expected Behavior

$::example_var => save => $::example_var
(nothing to change)

Steps to Reproduce

Open VScode and enable Puppet Vscode Extension
Write a manifests referencing a top scope variable.
It is rewritten into a reference to a fact.

Environment

Since Puppet VSCode extension 1.5.0

Seems correct to me. What top scope variables are you using?

The vscode extension assumes that all top scope variables are facts, which is not true.

You can have a variable defined in you "entrypoint" manifest that defines a variable to be used globally.

I'm not meaning this is the right thing to do (and I would even advise against...), however the current behavior prevents you from doing something that is possible in the language.

For example on one setup involving arm devices, I have the following piece of code because of repository naming;

//nodes.pp
$arch = $facts['os']['architecture'] ? {
  'aarch64' => 'arm64',
  'aarch'   => 'arm',
  default   => $facts['os']['architecture']
}

Current VSCode behavior prevents me from referring to this variable, it keeps turning it into a facts, which it is not.

Hope this makes sense

In that case, shouldn't you be referring to it as $nodes::arch when used in other classes?

node.pp is an example entrypoint, may be be calling it site.pp would have been clearer but it is not a class

The documentation is here: https://www.puppet.com/docs/puppet/8/lang_scope.html#top-scope

Notably: Because the top scope’s name is the empty string, $::my_variable refers to the top-scope value of $my_variable, even if $my_variable has a different value in local scope.

Which clearly states that we must be able to access top scope variables.

OK I see. I don't use top scope variables from a site.pp like that, so thanks for elaborating.