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

variable scoping change in Puppet 4.6.0

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: PUP 4.6.0
    • Fix Version/s: PUP 4.6.1
    • Component/s: None
    • Labels:
    • Template:
    • Story Points:
      1
    • Sprint:
      Language 2016-08-24
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      A regression in evaluation of resource like class inclusion caused evaluation of the class to be lazy as opposed to the correct immediate evaluation. This in turn led to problems with missing variables which in turn could lead to other problems. The order of evaluation is now restored.
      Show
      A regression in evaluation of resource like class inclusion caused evaluation of the class to be lazy as opposed to the correct immediate evaluation. This in turn led to problems with missing variables which in turn could lead to other problems. The order of evaluation is now restored.

      Description

      Variables defined in a class are not in scope after resource-like declaration of that class:

      $ cat test.pp 
      class a($myvar = 'hello') {}
      class { 'a': myvar => 'goodbye' }
      notify { $a::myvar: }
       
      $ puppet --version
      4.5.3
      $ puppet apply --strict_variables test.pp 
      Notice: Compiled catalog for kvm-01.node.vagrant.consul in environment production in 0.03 seconds
      Notice: goodbye
      Notice: /Stage[main]/Main/Notify[goodbye]/message: defined 'message' as 'goodbye'
      Notice: Applied catalog in 0.02 seconds
       
      $ puppet --version
      4.6.0
      $ puppet apply --strict_variables test.pp 
      Error: Evaluation Error: Unknown variable: 'a::myvar'. at /home/vagrant/test.pp:3:10 on node kvm-01.node.vagrant.consul
      

      Without strict_variables it could be very dangerous. Note that if you add an include, it works:

      $ cat test.pp 
      class a($myvar = 'hello') {}
      class { 'a': myvar => 'goodbye' }
      include a
      notify { $a::myvar: } 
       
      $ puppet --version
      4.6.0
      $ puppet apply --strict_variables test.pp 
      Notice: Compiled catalog for kvm-01.node.vagrant.consul in environment production in 0.09 seconds
      Notice: goodbye
      Notice: /Stage[main]/Main/Notify[goodbye]/message: defined 'message' as 'goodbye'
      Notice: Applied catalog in 0.02 seconds
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mmickan Mark Mickan
              • Votes:
                7 Vote for this issue
                Watchers:
                21 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support