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

unexpected different behaviour of 0 (integer vs. string) as a value in Hiera and as a default value for class parameters

    Details

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

      Description

      I'm not sure, if this should be considered as an error. At least it should be stressed in the documentation:

      0 (a digit) used as default value of a class parameter is converted into a string or character when the variable is interpreted in a template by Ruby.
      On the other hand, 0 entered as a value in an hiera-yaml file is interpreted as an integer value for the same template.

      modules/test/manifests/init.pp:
      class test (
      $foobar = 0
      )
      {
      file

      { '/tmp/test': ensure => file, content => template("$module_name/test.erb"), }

      }

      modules/test/templates/init.erb:
      <% if foobar %>
      foobar
      <% end %>
      <% if foobar == '' %>
      foobar == ''
      <% end %>
      <% if foobar == '0' %>
      foobar == '0'
      <% end %>
      <% if foobar == 0 %>
      foobar == 0
      <% end %>
      <% if foobar == true %>
      foobar == true
      <% end %>

      --------------------------------------------
      node.yaml:

      classes:

      • test

      => /tmp/test:
      foobar
      foobar == '0'

      --------------------------------------------
      node.yaml:

      classes:

      • test

      test::foobar:

      => /tmp/test:
      foobar
      foobar == '0'

      --------------------------------------------
      node.yaml:

      classes:

      • test

      test::foobar: 0

      => /tmp/test:
      foobar
      foobar == 0

      --------------------------------------------
      node.yaml:

      classes:

      • test

      test::foobar: '0'

      => /tmp/test:
      foobar
      foobar == '0'

      --------------------------------------------
      node.yaml:

      classes:

      • test

      test::foobar: true

      => /tmp/test:
      foobar
      foobar == true

      --------------------------------------------
      node.yaml:

      classes:

      • test

      test::foobar: false

      => /tmp/test:
      <empty>

      --------------------------------------------
      node.yaml:

      classes:

      • test

      test::foobar: 1

      => /tmp/test:
      foobar

        Attachments

          Activity

            People

            • Assignee:
              ap Andreas Papst
              Reporter:
              ap Andreas Papst
              QA Contact:
              Kurt Wall
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Zendesk Support