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

variable scoping change in Puppet 4.6.0

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • PUP 4.6.0
    • PUP 4.6.1
    • None
    • 1
    • Language 2016-08-24
    • Bug Fix
    • 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

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

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support