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

bad conversion from hash to yaml using .to_yaml function

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: PUP 3.8.7
    • Fix Version/s: None
    • Component/s: Language
    • Labels:
    • Environment:

      root@agent01:~# uname -a
      Linux agent01 3.13.0-98-generic #145-Ubuntu SMP Sat Oct 8 20:13:07 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

      root@agent01:~# puppet --version
      3.8.7

    • Template:
    • Acceptance Criteria:
      Hide

      correct output:


      string1: Test String
      string2: Test String
      string3: my string
      Integer1: '123'
      Integer2: '123'
      Integer3: 123
      vector1:

      • '1'
      • '2'
      • '3'
        vector2:
      • '1'
      • '2'
      • '3'
        vector3:
      • 1
      • 2
      • 3
        hash1:
        a: '1'
        b: '2'
        c: '3'
        hash2:
        a: '1'
        b: '2'
        c: '3'
        hash3:
        a: 1
        b: 2
        c: 3
      Show
      correct output: — string1: Test String string2: Test String string3: my string Integer1: '123' Integer2: '123' Integer3: 123 vector1: '1' '2' '3' vector2: '1' '2' '3' vector3: 1 2 3 hash1: a: '1' b: '2' c: '3' hash2: a: '1' b: '2' c: '3' hash3: a: 1 b: 2 c: 3

      Description

      Bad conversion from hash to yaml in puppet template .erb using function to_yaml

      *---- beging how to reproduce ----
      sudo mkdir -p /var/lib/puppet/templates/
       
      cat > /var/lib/puppet/templates/test.erb << _EOF
      <% if @hash_to_render -%>
      <%= @hash_to_render.to_yaml %>
      <% end -%>
      _EOF
       
      cat > ~/test.pp << _EOF
       
      \$my_string = 'my string'
       
      \$hash_to_render = {
        'string1'  => 'Test String',
        'string2'  => "Test String",
        'string3'  => "\${my_string}",
        'Integer1' => '123',
        'Integer2' => "123",
        'Integer3' => 123,
        'vector1'  => ['1','2','3'],
        'vector2'  => ["1","2","3"],
        'vector3'  => [1,2,3],
        'hash1'    => { 'a' => '1', 'b' => '2', 'c' => '3' },
        'hash2'    => { "a" => "1", "b" => "2", "c" => "3" },
        'hash3'    => { a => 1, b => 2, c => 3 },
      }
       
      file { '/tmp/test-out.yml':
      	ensure  => 'file',
      	content => template('test.erb'),
      }
      _EOF
       
      puppet apply test.pp 
       
      cat /tmp/test-out.yml
       
      *---- end how to reproduce ----
      

      * Incorrect Output
      --- 
        string1: "Test String"
        string2: "Test String"
        string3: "my string"
        Integer1: "123"
        Integer2: "123"
        Integer3: "123"
        vector1: 
          - "1"
          - "2"
          - "3"
        vector2: 
          - "1"
          - "2"
          - "3"
        vector3: 
          - "1"
          - "2"
          - "3"
        hash1: 
          a: "1"
          b: "2"
          c: "3"
        hash2: 
          a: "1"
          b: "2"
          c: "3"
        hash3: 
          a: "1"
          b: "2"
          c: "3"
      

        Attachments

          Activity

            People

            • Assignee:
              christiangda Christian Gonzalez
              Reporter:
              christiangda Christian Gonzalez
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Zendesk Support