{"record":{"id":"4e6ee899e1754dcc","repo":"puppetlabs/puppet","slug":"purging-is-only-supported-on-types-that-accept-en","errorCode":null,"errorMessage":"Purging is only supported on types that accept 'ensure'","messagePattern":"Purging is only supported on types that accept 'ensure'","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/resources.rb","lineNumber":38,"sourceCode":"\n    munge(&:to_s)\n  end\n\n  newparam(:purge, :boolean => true, :parent => Puppet::Parameter::Boolean) do\n    desc \"Whether to purge unmanaged resources.  When set to `true`, this will\n      delete any resource that is not specified in your configuration and is not\n      autorequired by any managed resources. **Note:** The `ssh_authorized_key`\n      resource type can't be purged this way; instead, see the `purge_ssh_keys`\n      attribute of the `user` type.\"\n\n    defaultto :false\n\n    validate do |value|\n      if munge(value)\n        unless @resource.resource_type.respond_to?(:instances)\n          raise ArgumentError, _(\"Purging resources of type %{res_type} is not supported, since they cannot be queried from the system\") % { res_type: @resource[:name] }\n        end\n        raise ArgumentError, _(\"Purging is only supported on types that accept 'ensure'\") unless @resource.resource_type.validproperty?(:ensure)\n      end\n    end\n  end\n\n  newparam(:unless_system_user) do\n    desc \"This keeps system users from being purged.  By default, it\n      does not purge users whose UIDs are less than the minimum UID for the system (typically 500 or 1000), but you can specify\n      a different UID as the inclusive limit.\"\n\n    newvalues(:true, :false, /^\\d+$/)\n\n    munge do |value|\n      case value\n      when /^\\d+/\n        Integer(value)\n      when :true, true\n        @resource.class.system_users_max_uid\n      when :false, false","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/resources.rb#L20-L56","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Custom type authors who modeled read-only inventory types (params only); framework code that emits purge for all discovered types without filtering.","solutions":["Remove purge for that type","Add an `ensure` property (newproperty(:ensure) with present/absent) to the custom type so instances can be removed","Manage that type's resources explicitly instead of purging"],"exampleFix":"# custom type before: params only, no ensure\nPuppet::Type.newtype(:mything) do\n  newparam(:name)\nend\n\n# after: ensure added, purge becomes possible\nPuppet::Type.newtype(:mything) do\n  newparam(:name)\n  newproperty(:ensure) do\n    newvalues(:present, :absent)\n    defaultto :present\n  end\nend","handlingStrategy":"validation","validationCode":"t = Puppet::Type.type(type_name.to_sym)\nif t&.respond_to?(:instances) && !t.validproperty?(:ensure)\n  # skip purge; type cannot be driven to absent\nend","typeGuard":"def purgeable?(type_name)\n  t = Puppet::Type.type(type_name.to_sym)\n  !t.nil? && t.respond_to?(:instances) && t.validproperty?(:ensure)\nend","tryCatchPattern":"begin\n  Puppet::Type.type(:resources).new(name: 'mycustom', purge: true)\nrescue ArgumentError => e\n  raise unless e.message.include?(\"accept 'ensure'\")\n  # add ensure to the custom type or drop purge\nend","preventionTips":["Audit purge declarations against type capabilities with rspec-puppet","Custom types intended for management need both self.instances and ensure","Keep purge restricted to a whitelist (user, group, mount, ...)"],"tags":["puppet","purge","metatype","custom-type"],"backgroundTag":"unsupported-operation","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}