puppetlabs/puppet · error · ArgumentError
manifest_file or code_string cannot be given when configured
Error message
manifest_file or code_string cannot be given when configured_by_env is true
What it means
PAL environment setup raises ArgumentError when configured_by_env: true is combined with manifest_file or code_string. configured_by_env means 'take the code from Puppet settings' (it then uses Puppet[:manifest]), so an inline manifest or code string is a conflicting input.
Source
Thrown at lib/puppet/pal/pal_impl.rb:77
def self.with_script_compiler(
configured_by_env: false,
manifest_file: nil,
code_string: nil,
facts: {},
variables: {},
set_local_facts: true,
&block
)
# TRANSLATORS: do not translate variable name strings in these assertions
assert_mutually_exclusive(manifest_file, code_string, 'manifest_file', 'code_string')
assert_non_empty_string(manifest_file, 'manifest_file', true)
assert_non_empty_string(code_string, 'code_string', true)
assert_type(T_BOOLEAN, configured_by_env, "configured_by_env", false)
if configured_by_env
unless manifest_file.nil? && code_string.nil?
# TRANSLATORS: do not translate the variable names in this error message
raise ArgumentError, _("manifest_file or code_string cannot be given when configured_by_env is true")
end
# Use the manifest setting
manifest_file = Puppet[:manifest]
elsif manifest_file.nil? && code_string.nil?
# An "undef" code_string is the only way to override Puppet[:manifest] & Puppet[:code] settings since an
# empty string is taken as Puppet[:code] not being set.
#
code_string = 'undef'
end
previous_tasks_value = Puppet[:tasks]
previous_code_value = Puppet[:code]
Puppet[:tasks] = true
# After the assertions, if code_string is non nil - it has the highest precedence
Puppet[:code] = code_string unless code_string.nil?
# If manifest_file is nil, the #main method will use the env configured manifestView on GitHub (pinned to e227c27540)
Solutions
- Drop configured_by_env (default false) when you pass manifest_file or code_string
- Or keep configured_by_env: true and omit manifest_file/code_string, setting Puppet[:manifest]/Puppet[:code] instead
- Audit wrapper code so the two options cannot both reach PAL
Example fix
# before
Puppet::Pal.with_script_compiler(code_string: code, configured_by_env: true) { |c| }
# after
Puppet::Pal.with_script_compiler(code_string: code) { |c| } Defensive patterns
Strategy: validation
Validate before calling
if configured_by_env && (manifest_file || code_string) raise ArgumentError, 'cannot combine configured_by_env with manifest_file/code_string' end
Prevention
- Decide one code source per call site: settings (configured_by_env) or explicit code/manifest
- Do not default configured_by_env to true in wrappers that also accept code_string
When it happens
Trigger: Puppet::Pal.with_script_compiler(manifest_file: 'site.pp', configured_by_env: true), or any PAL entry call passing both code_string and configured_by_env: true.
Common situations: Wrappers that always forward a code_string option into PAL while defaulting configured_by_env to true; migrating older PAL code that tolerated the combination; scripts that want Puppet[:code] but also pass a string.
Related errors
- Given data_type value is not a data type, got '%{type}'
- Given variables must be a hash, got %{type}
- Cannot use '%{a_term}' and '%{b_term}' at the same time
- puppet.tasks/unparseable-metadata
- Invalid terminus name %{terminus_class}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/2f52918ecbe8cebf.
Report an issue: GitHub.