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

Unset metaparameters throw strict_variables errors

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.0.0
    • Fix Version/s: PUP 4.3.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Puppet 4.0+ with strict_variables=true

    • Template:

      Description

      The documentation for metaparameters implies that they are available to every resource, but when strict_variables=true, some unset metaparameters are not assigned default values.

      In the following test code, neither the $name nor the $schedule metaparameters are explicitly set, but only the $schedule reference aborts compilation.

      The following code fails with strict_variables=true

      B {
        schedule => undef,
      }
      define a {
        notify { $name:
          message => 'Success',
        }
      }
      define b {
        a { $name:
          schedule => $schedule,
        }
      }
      b { 'no schedule': }
      

      Error

      Evaluation Error: Unknown variable: 'schedule'. at test.pp:11:17

      Explicitly setting the metaparameter results in a warning

      define a {
        notify { $name:
          message => 'Success',
        }
      }
      define b (
        $schedule = undef,
      )
      {
        a { $name:
          schedule => $schedule,
        }
      }
      b { 'no schedule': }
      

      Warning

      schedule is a metaparam; this value will inherit to all contained resources in the b definition

      Currently, I am using the following ugly workaround

      define a {
        notify { $name:
          message => 'Success',
        }
      }
      define b {
        $strict = defined('$::settings::strict_variables') and $::settings::strict_variables
        if $strict and !defined('$schedule') {
          $schedule = undef
        }
        a { $name:
          schedule => $schedule,
        }
      }
      b { 'no schedule': }
      

      Notice

      Success

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                rvincentatprokarmadotcom Bob Vincent
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support