puppetlabs/puppet · error · ArgumentError

Purging is only supported on types that accept 'ensure'

Error message

Purging is only supported on types that accept 'ensure'

What it means

Purging works by ensuring `absent` on unmanaged instances, so the purged type must have an `ensure` property. The purge validate raises ArgumentError "Purging is only supported on types that accept 'ensure'" (lib/puppet/type/resources.rb:38) when `validproperty?(:ensure)` is false — e.g. types that define only parameters.

Source

Thrown at lib/puppet/type/resources.rb:38

    munge(&:to_s)
  end

  newparam(:purge, :boolean => true, :parent => Puppet::Parameter::Boolean) do
    desc "Whether to purge unmanaged resources.  When set to `true`, this will
      delete any resource that is not specified in your configuration and is not
      autorequired by any managed resources. **Note:** The `ssh_authorized_key`
      resource type can't be purged this way; instead, see the `purge_ssh_keys`
      attribute of the `user` type."

    defaultto :false

    validate do |value|
      if munge(value)
        unless @resource.resource_type.respond_to?(:instances)
          raise ArgumentError, _("Purging resources of type %{res_type} is not supported, since they cannot be queried from the system") % { res_type: @resource[:name] }
        end
        raise ArgumentError, _("Purging is only supported on types that accept 'ensure'") unless @resource.resource_type.validproperty?(:ensure)
      end
    end
  end

  newparam(:unless_system_user) do
    desc "This keeps system users from being purged.  By default, it
      does not purge users whose UIDs are less than the minimum UID for the system (typically 500 or 1000), but you can specify
      a different UID as the inclusive limit."

    newvalues(:true, :false, /^\d+$/)

    munge do |value|
      case value
      when /^\d+/
        Integer(value)
      when :true, true
        @resource.class.system_users_max_uid
      when :false, false

View on GitHub (pinned to e227c27540)

Solutions

  1. Remove purge for that type
  2. Add an `ensure` property (newproperty(:ensure) with present/absent) to the custom type so instances can be removed
  3. Manage that type's resources explicitly instead of purging

Example fix

# custom type before: params only, no ensure
Puppet::Type.newtype(:mything) do
  newparam(:name)
end

# after: ensure added, purge becomes possible
Puppet::Type.newtype(:mything) do
  newparam(:name)
  newproperty(:ensure) do
    newvalues(:present, :absent)
    defaultto :present
  end
end
Defensive patterns

Strategy: validation

Validate before calling

t = Puppet::Type.type(type_name.to_sym)
if t&.respond_to?(:instances) && !t.validproperty?(:ensure)
  # skip purge; type cannot be driven to absent
end

Type guard

def purgeable?(type_name)
  t = Puppet::Type.type(type_name.to_sym)
  !t.nil? && t.respond_to?(:instances) && t.validproperty?(:ensure)
end

Try / catch

begin
  Puppet::Type.type(:resources).new(name: 'mycustom', purge: true)
rescue ArgumentError => e
  raise unless e.message.include?("accept 'ensure'")
  # add ensure to the custom type or drop purge
end

Prevention

When it happens

Trigger: `resources { 'exec': purge => true }`; a custom type that implements self.instances but defines no `newproperty(:ensure)`; generically generated purge blocks applied to every type in the environment.

Common situations: Custom type authors who modeled read-only inventory types (params only); framework code that emits purge for all discovered types without filtering.

Related errors


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