puppetlabs/puppet · error · ArgumentError

The output directory '%{outputdir}' exists and is not a dire

Error message

The output directory '%{outputdir}' exists and is not a directory

What it means

Raised by `puppet generate types` when the per-environment output directory `<envroot>/.resource_types` exists but is not a directory (typically a regular file). The face happily creates the directory when it is absent (`mkpath`), but refuses to clobber an existing non-directory path, so the run stops before generating anything.

Source

Thrown at lib/puppet/face/generate.rb:58

    end

    option '--force' do
      summary _('Forces the generation of output files (skips up-to-date checks).')
      default_to { false }
    end

    when_invoked do |options|
      generator = Puppet::Generate::Type
      inputs = generator.find_inputs(options[:format].to_sym)
      environment = Puppet.lookup(:current_environment)

      # get the common output directory (in <envroot>/.resource_types) - create it if it does not exists
      # error if it exists and is not a directory
      #
      path_to_env = environment.configuration.path_to_env
      outputdir = File.join(path_to_env, '.resource_types')
      if Puppet::FileSystem.exist?(outputdir) && !Puppet::FileSystem.directory?(outputdir)
        raise ArgumentError, _("The output directory '%{outputdir}' exists and is not a directory") % { outputdir: outputdir }
      end

      Puppet::FileSystem.mkpath(outputdir)

      generator.generate(inputs, outputdir, options[:force])

      exit(1) if generator.bad_input?
      nil
    end
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Inspect the path: `ls -la <envroot>/.resource_types`
  2. If it is a stray file, remove or rename it (`mv .resource_types .resource_types.bak`)
  3. Re-run `puppet generate types` — it now creates a proper directory and generates into it
  4. Fix the pipeline step that created a file instead of `mkdir -p`

Example fix

# before
ls -la production/.resource_types    # regular file → error
# after
rm production/.resource_types
puppet generate types --environment production
Defensive patterns

Strategy: validation

Validate before calling

outdir = File.join(env.configuration.path_to_env, '.resource_types')
if File.exist?(outdir) && !File.directory?(outdir)
  abort "#{outdir} exists and is not a directory"
end

Type guard

def resource_types_dir_writable?(env)
  path = File.join(env.configuration.path_to_env, '.resource_types')
  !File.exist?(path) || File.directory?(path)
end

Prevention

When it happens

Trigger: `puppet generate types --environment <env>` where `<envroot>/.resource_types` was previously created as a file — e.g. a `touch .resource_types` marker, a botched deploy script, or an interrupted earlier run that left a file behind.

Common situations: Deploy tooling that creates marker files; environment code dirs restored from archives with wrong file types; puppet.conf environmentpath pointing somewhere unexpected so the same name collides.

Related errors


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