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

ensure data binding for class params can produce undef

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Duplicate
    • Affects Version/s: PUP 3.7.2
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
    • Template:

      Description

      Assuming this class:

      class testing::cwood1 ( $param1 ) {
        # stuff
      }
      

      And having a yaml null in my hieradata, or a key with no value, like either of these:

      testing::cwood1::param1: null
      testing::cwood1::param1: ~
      testing::cwood1::param1:
      

      I get errors about how the class needs a parameter.

      Feb 10 11:14:05 puppetmaster2dev puppet-master[7546]: Must pass param1 to Class[Testing::Cwood1] at /etc/puppet/environments/production/modules/testing/manifests/init.pp:3 on node pt1.me.com
      

      With an explicitly empty string I do not see this error, the class parameter is accepted.

      testing::cwood1::param1: ''
      

      The problem is that the class doesn't pick up how I've defined the hiera key "testing::cwood1::param1". Nevertheless the key is there and I am passing something, even if I am passing a representation of nothing.

      I expected that this might have the same result as doing "$param1 = undef" since the undef there is the closest thing in puppet to ruby nil, yaml null. That said, there are a number of interesting tickets about true/truthy/false/nil handling and I will link those here since it's probably a subset of those issues.

      Further, a straight command-line hiera lookup appears to represent these as nil.

      [root@puppetmaster2dev ~]# grep testing::cwood1::param1 /etc/puppet/environments/production/hieradata/nodes/pt1.me.com.eyaml 
      testing::cwood1::param1: null
      [root@puppetmaster2dev ~]# hiera testing::cwood1::param1 environment=production fqdn=pt1.me.com
      nil
       
      [root@puppetmaster2dev ~]# grep testing::cwood1::param1 /etc/puppet/environments/production/hieradata/nodes/pt1.me.com.eyaml 
      testing::cwood1::param1: ~
      [root@puppetmaster2dev ~]# hiera testing::cwood1::param1 environment=production fqdn=pt1.me.com
      nil
      

      A quick yaml read picks these up as nil, as well.

      #!/usr/bin/env ruby
       
      require 'pp'
      require 'yaml'
       
      data = File.read(ARGV[0])
      yaml = YAML.load(data)
      pp yaml
      

      YAML nulls:

      http://yaml.org/type/null.html
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              cwood Christopher Wood
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support