puppetlabs/puppet · error · Puppet::Module::MissingModule

Module %{module_name} not found in environment %{environment

Error message

Module %{module_name} not found in environment %{environment_name}.

What it means

TaskInformationService.task_data is the task counterpart of plan_data: after resolving the environment, Puppet::Module.find(module_name, environment_name) returning nil raises Puppet::Module::MissingModule. The environment exists but contains no module by that name in its modulepath. It backs 'puppet task show' / 'puppet task run' metadata lookups and Puppet Server task APIs.

Source

Thrown at lib/puppet/info_service/task_information_service.rb:29

      mod.tasks.map do |task|
        # If any task is malformed continue to list other tasks in module

        task.validate
        { :module => { :name => task.module.name }, :name => task.name, :metadata => task.metadata }
      rescue Puppet::Module::Task::Error => err
        Puppet.log_exception(err)
        nil
      end
    end.flatten.compact
  end

  def self.task_data(environment_name, module_name, task_name)
    # raise EnvironmentNotFound if applicable
    Puppet.lookup(:environments).get!(environment_name)

    pup_module = Puppet::Module.find(module_name, environment_name)
    if pup_module.nil?
      raise Puppet::Module::MissingModule, _("Module %{module_name} not found in environment %{environment_name}.") %
                                           { module_name: module_name, environment_name: environment_name }
    end

    task = pup_module.tasks.find { |t| t.name == task_name }
    if task.nil?
      raise Puppet::Module::Task::TaskNotFound.new(task_name, module_name)
    end

    begin
      task.validate
      { :metadata => task.metadata, :files => task.files }
    rescue Puppet::Module::Task::Error => err
      { :metadata => nil, :files => [], :error => err.to_h }
    end
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Check the module exists in that environment: ls $(puppet config print environmentpath)/<env>/modules/<module>
  2. Redeploy the environment code (r10k deploy environment <env> or Code Manager) if the module should be there
  3. Use the fully-qualified task name matching module directory casing: <module>/<task>
  4. Verify with `puppet task show --environment <env>` that the task is discoverable before programmatic calls

Example fix

# before
Puppet::InfoService::TaskInformationService.task_data('production', 'package', 'init')
# => Puppet::Module::MissingModule: Module package not found in environment production.

# after: deploy module then retry
r10k deploy environment production -p
Puppet::InfoService::TaskInformationService.task_data('production', 'package', 'init')
Defensive patterns

Strategy: validation

Validate before calling

Puppet.lookup(:environments).get!(environment_name)
raise Puppet::Module::MissingModule if Puppet::Module.find(module_name, environment_name).nil?
data = Puppet::InfoService::TaskInformationService.task_data(environment_name, module_name, task_name)

Try / catch

begin
  data = Puppet::InfoService::TaskInformationService.task_data(env, mod, task)
rescue Puppet::Module::MissingModule
  data = nil  # caller reports 'task not deployed' without a stack trace
end

Prevention

When it happens

Trigger: Calling Puppet::InfoService::TaskInformationService.task_data('production', 'package', 'install') when the package module is not deployed to production; wrong environment argument; module name case mismatch with the directory; task invoked from a node whose environment lacks the module.

Common situations: Running Bolt/puppet task against an environment where code deployment (r10k/Code Manager) had not yet synced the module; renames of task modules; typos in the module segment of task names (module::task).

Related errors


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