puppetlabs/puppet · error · ArgumentError

No directory found for the environment '%{env_name}' on the

Error message

No directory found for the environment '%{env_name}' on the path '%{envpath}'

What it means

When in_environment is given envpath (one or more parent directories, colon-separated), PAL resolves env_name by searching each directory for a subdirectory of that name. If no environment directory is found on any entry, it raises ArgumentError listing the environment name and the path searched.

Source

Thrown at lib/puppet/pal/pal_impl.rb:323

      env = Puppet::Node::Environment.create(env_name, pre_modulepath + mid_modulepath + post_modulepath)
      environments = Puppet::Environments::StaticDirectory.new(env_name, env_dir, env) # The env being used is the only one...
    else
      assert_non_empty_string(envpath, 'envpath')

      # The environment is resolved against the envpath. This is setup without a basemodulepath
      # The modulepath defaults to the 'modulepath' in the found env when "Directories" is used
      #
      if envpath.is_a?(String) && envpath.include?(File::PATH_SEPARATOR)
        # potentially more than one directory to search
        env_loaders = Puppet::Environments::Directories.from_path(envpath, [])
        environments = Puppet::Environments::Combined.new(*env_loaders)
      else
        environments = Puppet::Environments::Directories.new(envpath, [])
      end
      env = environments.get(env_name)
      if env.nil?
        raise ArgumentError, _("No directory found for the environment '%{env_name}' on the path '%{envpath}'") % { env_name: env_name, envpath: envpath }
      end

      # A given modulepath should override the default
      mid_modulepath = modulepath.nil? ? env.modulepath : modulepath
      env_path = env.configuration.path_to_env
      env = env.override_with(:modulepath => pre_modulepath + mid_modulepath + post_modulepath)
      # must configure this in case logic looks up the env by name again (otherwise the looked up env does
      # not have the same effective modulepath).
      environments = Puppet::Environments::StaticDirectory.new(env_name, env_path, env) # The env being used is the only one...
    end
    in_environment_context(environments, env, facts, variables, &block)
  end

  # Prepares the puppet context with pal information - and delegates to the block
  # No set up is performed at this step - it is delayed until it is known what the
  # operation is going to be (for example - using a ScriptCompiler).
  #
  def self.in_environment_context(environments, env, facts, variables, &block)

View on GitHub (pinned to e227c27540)

Solutions

  1. Pre-check that some envpath entry contains the env: envpath.split(File::PATH_SEPARATOR).any? { |d| File.directory?(File.join(d, env_name)) }
  2. Fix the environment name spelling or casing
  3. Point envpath at the parent directory that actually holds the environment directories (or deploy the environment)

Example fix

# before
Puppet::Pal.in_environment('prod', envpath: '/etc/puppetlabs/code/environments/production')

# after
Puppet::Pal.in_environment('prod', envpath: '/etc/puppetlabs/code/environments') { |pal| }
Defensive patterns

Strategy: validation

Validate before calling

found = envpath.split(File::PATH_SEPARATOR).any? { |d| File.directory?(File.join(d, env_name)) }
raise ArgumentError, "environment '#{env_name}' missing on #{envpath}" unless found

Prevention

When it happens

Trigger: in_environment('produktion', envpath: '/etc/puppetlabs/code/environments') where only production/ exists; envpath pointing at the environment directory itself instead of its parent; empty envpath directory.

Common situations: Typo'd environment name; wrong envpath level (passing .../environments/production instead of .../environments); case-sensitive filesystem mismatches; environment not deployed to that path.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/f75cf289f13e6c41. Report an issue: GitHub.