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

defining hash keys with any expression does not work

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
    • Template:

      Description

      Given the following manifest:

      $key = 'bla'
      $value = 'bla'
       
      $test_hash = {
        $key => $value
      }
       
      notice $test_hash
      

      This raises the following error:

      $ puppet apply test.pp --trace --debug
      Error: Could not parse for environment production: Syntax error at 'key'; expected '}' at /tmp/test.pp:7 on node foo
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/parser_support.rb:134:in `on_error'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/lexer.rb:480:in `scan'
      (eval):3:in `_racc_yyparse_c'
      (eval):3:in `yyparse'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/parser_support.rb:145:in `parse'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/node/environment.rb:216:in `perform_initial_import'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/node/environment.rb:85:in `block in known_resource_types'
      /home/duritong/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/node/environment.rb:82:in `known_resource_types'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/resource/type_collection_helper.rb:5:in `known_resource_types'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:415:in `initvars'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:182:in `initialize'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:29:in `new'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:29:in `compile'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/catalog/compiler.rb:77:in `block in compile'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/util.rb:184:in `benchmark'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/catalog/compiler.rb:75:in `compile'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/catalog/compiler.rb:35:in `find'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/indirection.rb:191:in `find'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application/apply.rb:204:in `main'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application/apply.rb:146:in `run_command'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:346:in `block (2 levels) in run'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:438:in `plugin_hook'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:346:in `block in run'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/util.rb:496:in `exit_on_fail'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:346:in `run'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/util/command_line.rb:87:in `execute'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/bin/puppet:4:in `<top (required)>'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/puppet:19:in `load'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/puppet:19:in `<main>'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `eval'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `<main>'
      Error: Could not parse for environment production: Syntax error at 'key'; expected '}' at /tmp/test.pp:7 on node foo
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/parser_support.rb:134:in `on_error'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/lexer.rb:480:in `scan'
      (eval):3:in `_racc_yyparse_c'
      (eval):3:in `yyparse'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/parser_support.rb:145:in `parse'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/node/environment.rb:216:in `perform_initial_import'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/node/environment.rb:85:in `block in known_resource_types'
      /home/duritong/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/node/environment.rb:82:in `known_resource_types'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/resource/type_collection_helper.rb:5:in `known_resource_types'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:415:in `initvars'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:182:in `initialize'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:29:in `new'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/parser/compiler.rb:29:in `compile'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/catalog/compiler.rb:77:in `block in compile'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/util.rb:184:in `benchmark'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/catalog/compiler.rb:75:in `compile'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/catalog/compiler.rb:35:in `find'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/indirector/indirection.rb:191:in `find'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application/apply.rb:204:in `main'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application/apply.rb:146:in `run_command'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:346:in `block (2 levels) in run'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:438:in `plugin_hook'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:346:in `block in run'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/util.rb:496:in `exit_on_fail'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/application.rb:346:in `run'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/lib/puppet/util/command_line.rb:87:in `execute'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/gems/puppet-3.0.2/bin/puppet:4:in `<top (required)>'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/puppet:19:in `load'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/puppet:19:in `<main>'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `eval'
      /home/duritong/.rvm/gems/ruby-1.9.3-p374/bin/ruby_noexec_wrapper:14:in `<main>'
      

      putting the key into quotes is a workaround:

      $ cat test.pp 
       
       
      $key = 'bla'
      $value = 'bla'
       
      $test_hash = {
        "${key}" => $value
      }
       
      notice $test_hash
      $ puppet apply test.pp --trace 
      Notice: Scope(Class[main]): {"bla"=>"bla"}
      Notice: Finished catalog run in 0.05 seconds
      

      This can be observed in 2.7.19 and 3.0.2

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            redmine.exporter redmine.exporter
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support