puppetlabs/puppet · error · Puppet::ParseError
Could not find data item %{key} in any Hiera data file and n
Error message
Could not find data item %{key} in any Hiera data file and no default supplied What it means
HieraPuppet.lookup raises Puppet::ParseError when hiera.lookup returns nil and no default was passed: the key had no value at any level of the hierarchy. The legacy hiera() function is a fail-if-miss exact lookup by design, so a miss without a default is fatal at compile time.
Source
Thrown at lib/hiera_puppet.rb:16
# frozen_string_literal: true
Puppet.features.hiera?
require 'hiera/scope'
require_relative 'puppet'
module HieraPuppet
module_function
def lookup(key, default, scope, override, resolution_type)
scope = Hiera::Scope.new(scope)
answer = hiera.lookup(key, default, scope, override, resolution_type)
if answer.nil?
raise Puppet::ParseError, _("Could not find data item %{key} in any Hiera data file and no default supplied") % { key: key }
end
answer
end
def parse_args(args)
# Functions called from Puppet manifests like this:
#
# hiera("foo", "bar")
#
# Are invoked internally after combining the positional arguments into a
# single array:
#
# func = function_hiera
# func(["foo", "bar"])
#
# Functions called from templates preserve the positional arguments:
#View on GitHub (pinned to e227c27540)
Solutions
- Supply an explicit default: hiera('mykey', 'sane-default')
- Add the key to the hierarchy level that should own it, then verify with: puppet lookup --explain mykey
- Fix the hierarchy in hiera.yaml (paths, datadir, backends) if every key misses
- Prefer the modern lookup() function with an explicit default_value over the deprecated hiera()
Example fix
# before
$port = hiera('myapp::port') # ParseError when key absent everywhere
# after
$port = lookup('myapp::port', Integer, 'first', 8080) Defensive patterns
Strategy: fallback
Validate before calling
answer = hiera.lookup(key, :__missing__, scope, override, resolution_type) if answer == :__missing__ answer = computed_default # or raise a domain-specific error end
Try / catch
begin
value = hiera('mykey')
rescue Puppet::ParseError
value = 'sane-default' # or lookup('mykey', 'sane-default') from the start
end Prevention
- Default to lookup('key', default) syntax so a miss is never fatal
- Verify keys exist with 'puppet lookup --explain key' before shipping profiles that depend on them
- Keep hierarchy paths in hiera.yaml tested in CI so misses are caught early
When it happens
Trigger: Calling hiera('mykey') in a manifest or scope.function_hiera(['mykey']) in a template when no hierarchy level defines mykey; also when the hierarchy or datadir is misconfigured so every lookup misses.
Common situations: Missing or typo'd key in hiera data; hiera.yaml hierarchy paths not matching the actual file layout; an eyaml/encrypted backend failing silently so nothing matches; code migrated from another site that assumed a default existed.
Related errors
- %{path}: file does not contain a valid yaml hash
- Unrecognized value for request 'merge' parameter: '%{merge}'
- Function lookup() did not find a value for the name '%{name}
- Unrecognized value for request 'merge' parameter: '#{merge}'
- Undefined variable '%{name}'; %{reason}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/8745b85e9cc8d73e.
Report an issue: GitHub.