Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-2130

Incosistent resolving of variable scoping for templates and manifests

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: PUP 2.7.25, PUP 3.4.3
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      A pristine puppet installation on any system desired

    • Template:

      Description

      Puppet 3 changed variable scoping and lookups. In the docs it is explicitly written that

      In effect, all variables will one of the following:

      Local
      Inherited from a base class
      Node-level
      Global

      The following PoC shows that there seems to be an exception to this rule as far as templates go.

      class a {
      notify{"bstring=${bstring} bstring=${b::bstring}":}
      $t = inline_template("bstring=<%= scope.lookupvar('b::bstring') %> bstring=<%= @bstring %>")
      notify{"t=${t}":}
      }

      class b {
      $bstring = "b"
      class

      { 'a': }

      }

      include b

      puppet apply on this manifest creates the following output

      Notice: bstring= bstring=b
      Notice: /Stage[main]/A/Notify[bstring= bstring=b]/message: defined 'message' as 'bstring= bstring=b'
      Notice: t=bstring=b bstring=b
      Notice: /Stage[main]/A/Notify[t=bstring=b bstring=b]/message: defined 'message' as 't=bstring=b bstring=b'

      While the first (for this run) notify is obviously correct and the variable ${bstring} variable is not looked up in the manifest, in the template evaluation @bstring is indeed evaluated, something that is not expected.

      Please do note that I added the scope.lookupvar('b::bstring') and ${b::bstring} parts as the canonical way to access the variable in each case.

      Also do note that this happens also on an hierarchy of classes that include each other (i.e d including c which includes b which includes a and d's variables are usable in a's templates)

      I suppose this should either be documented or fixed.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                andy Andrew Parker
                Reporter:
                akosiaris Alexandros Kosiaris
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support