{"record":{"id":"183335087a814690","repo":"puppetlabs/puppet","slug":"values-file-option-must-evaluate-to-a-hash-or-un","errorCode":null,"errorMessage":"--values_file option must evaluate to a Hash or undef/nil, got: '%{template_class}'","messagePattern":"--values_file option must evaluate to a Hash or undef/nil, got: '%(.+?)'","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/puppet/face/epp.rb","lineNumber":419,"sourceCode":"  def get_values(compiler, options)\n    template_values = nil\n    values_file = options[:values_file]\n    if values_file\n      begin\n        case values_file\n        when /\\.yaml$/\n          template_values = Puppet::Util::Yaml.safe_load_file(values_file, [Symbol])\n        when /\\.pp$/\n          evaluating_parser = Puppet::Pops::Parser::EvaluatingParser.new\n          template_values = evaluating_parser.evaluate_file(compiler.topscope, values_file)\n        else\n          Puppet.err(_(\"Only .yaml or .pp can be used as a --values_file\"))\n        end\n      rescue => e\n        Puppet.err(_(\"Could not load --values_file %{error}\") % { error: e.message })\n      end\n      unless template_values.nil? || template_values.is_a?(Hash)\n        Puppet.err(_(\"--values_file option must evaluate to a Hash or undef/nil, got: '%{template_class}'\") % { template_class: template_values.class })\n      end\n    end\n\n    values = options[:values]\n    if values\n      evaluating_parser = Puppet::Pops::Parser::EvaluatingParser.new\n      result = evaluating_parser.evaluate_string(compiler.topscope, values, 'values-hash')\n      case result\n      when nil\n        template_values\n      when Hash\n        template_values.nil? ? result : template_values.merge(result)\n      else\n        Puppet.err(_(\"--values option must evaluate to a Hash or undef, got: '%{values_class}'\") % { values_class: result.class })\n      end\n    else\n      template_values\n    end","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/face/epp.rb#L401-L437","documentation":"Logged by Puppet::Face[:epp]#get_values when --values_file loads successfully but evaluates to anything other than a Hash or nil — for example a YAML list, a scalar, or a .pp file whose last expression is an Array. Template parameters must be name-to-value pairs, so the values are discarded and rendering proceeds with none.","triggerScenarios":"`puppet epp render tpl.epp --values_file list.yaml` where the YAML top level is '- a\\n- b'; a .pp values file whose last statement returns a String or Array instead of a hash literal.","commonSituations":"YAML written as a list of key/value pairs instead of a mapping; .pp values files ending with an expression like $my_array instead of a hash literal.","solutions":["Make the top-level YAML structure a mapping (key: value lines, not '- key: value')","In a .pp values file, end with a literal hash: { a => 1, b => 2 }","Rerun and confirm the values reach the template parameters"],"exampleFix":"# before (values.yaml)\n- name: app\n- port: 8080\n\n# after\nname: app\nport: 8080","handlingStrategy":"validation","validationCode":"values = YAML.safe_load_file('values.yaml', [Symbol])\nabort 'values file top level must be a Hash (or empty)' unless values.nil? || values.is_a?(Hash)","typeGuard":"def template_values?(v)\n  v.nil? || v.is_a?(Hash)\nend","tryCatchPattern":null,"preventionTips":["Author values files as mappings, never lists of pairs","Check the loaded shape in the script that generates values files"],"tags":["ruby","puppet","yaml","epp","type-mismatch","values"],"backgroundTag":"template-values-type-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}