puppetlabs/puppet · error · Puppet::Settings::InterpolationError
Could not find value for %{expression}
Error message
Could not find value for %{expression} What it means
Puppet::Settings::ValuesFromSection#convert expands $name and ${name} tokens inside String setting values via gsub. After handling the environment special-case (only interpolatable where allowed) and run_mode, any other name is resolved with interpolate(varname.to_sym); when that returns nil, Puppet::Settings::InterpolationError 'Could not find value for $x' is raised. Variable names are restricted to word characters (\w+), so ::-qualified or dashed names can never resolve.
Source
Thrown at lib/puppet/settings.rb:1524
def convert(value, setting_name)
case value
when nil
nil
when String
failed_environment_interpolation = false
interpolated_value = value.gsub(/\$(\w+)|\$\{(\w+)\}/) do |expression|
varname = ::Regexp.last_match(2) || ::Regexp.last_match(1)
interpolated_expression =
if varname != ENVIRONMENT_SETTING || ok_to_interpolate_environment(setting_name)
if varname == ENVIRONMENT_SETTING && @environment
@environment
elsif varname == "run_mode"
@mode
elsif !(pval = interpolate(varname.to_sym)).nil?
pval
else
raise InterpolationError, _("Could not find value for %{expression}") % { expression: expression }
end
else
failed_environment_interpolation = true
expression
end
interpolated_expression
end
if failed_environment_interpolation
# TRANSLATORS '$environment' is a Puppet specific variable and should not be translated
Puppet.warning(_("You cannot interpolate $environment within '%{setting_name}' when using directory environments.") % { setting_name: setting_name } +
' ' + _("Its value will remain %{value}.") % { value: interpolated_value })
end
interpolated_value
else
value
end
end
View on GitHub (pinned to e227c27540)
Solutions
- Check the exact token from the message against `puppet config print` output to see if such a setting exists; fix typos.
- Declare the missing setting in the appropriate section, or replace the token with the literal value.
- Use only single-word setting names in interpolation ($name or ${name}); names with ::, dots, or dashes are invalid here by construction.
Example fix
# before (puppet.conf) [main] certdir = $ssldirf/certs # after [main] certdir = $ssldir/certs
Defensive patterns
Strategy: validation
Validate before calling
tokens = value.scan(/\$(?:\{(\w+)\}|(\w+))/).flatten.compact
tokens.each do |name|
next if name == 'environment' || name == 'run_mode'
raise Puppet::Error, "unknown interpolation target $#{name}" if Puppet.settings.setting(name.to_sym).nil?
end Type guard
resolvable_tokens = ->(v) { v.scan(/\$(?:\{(\w+)\}|(\w+))/).flatten.compact.all? { |n| %w[environment run_mode].include?(n) || !Puppet.settings.setting(n.to_sym).nil? } } Try / catch
begin
converted = Puppet.settings[:mysetting]
rescue Puppet::Settings::InterpolationError => e
raise unless e.message.include?('Could not find value for')
Puppet.err("#{e.message} — declare the setting or fix the typo")
raise
end Prevention
- Interpolate only single-word ($name / ${name}) references to settings you know exist
- Names with :: or dashes are never resolvable in settings interpolation
- Check `puppet config print` for the canonical setting name before referencing it
When it happens
Trigger: puppet.conf values like `certdir = $confdirf/ssl` (typo), `basemodulepath = $progdir:...` (setting does not exist), or referencing a setting removed in the current Puppet version; a ${vardir} token in a setting defined later or never defined; environment-variable-style names that were never Puppet settings.
Common situations: Hand-edited or templated puppet.conf with stale variable names; upgrading Puppet where a setting was removed/renamed and old configs still interpolate it; copying snippet configs from tutorials that assume settings the deployment never declared.
Related errors
- Error converting value for param '%{name}': %{detail}
- Global option %{option} does not exist in Puppet.settings
- Cannot use empty string as a class name
- Recursive lookup detected in [%{name_stack}]
- Invalid run mode '#{mode}'
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/51e8ee667df9e13b.
Report an issue: GitHub.