{"record":{"id":"968f73ecf584a7c8","repo":"puppetlabs/puppet","slug":"could-not-delete-resource-name-detail-968f73","errorCode":null,"errorMessage":"Could not delete %{resource} %{name}: %{detail}","messagePattern":"Could not delete %(.+?) %(.+?): %(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/nameservice.rb","lineNumber":182,"sourceCode":"      if feature?(:manages_password_age) && (cmd = passcmd)\n        execute(cmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment, :sensitive => sensitive })\n      end\n    rescue Puppet::ExecutionFailure => detail\n      raise Puppet::Error, _(\"Could not create %{resource} %{name}: %{detail}\") % { resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace\n    end\n  end\n\n  def delete\n    unless exists?\n      info _(\"already absent\")\n      # the object already doesn't exist\n      return nil\n    end\n\n    begin\n      execute(deletecmd, { :failonfail => true, :combine => true, :custom_environment => @custom_environment })\n    rescue Puppet::ExecutionFailure => detail\n      raise Puppet::Error, _(\"Could not delete %{resource} %{name}: %{detail}\") % { resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace\n    end\n  end\n\n  def ensure\n    if exists?\n      :present\n    else\n      :absent\n    end\n  end\n\n  # Does our object exist?\n  def exists?\n    !!getinfo(true)\n  end\n\n  # Retrieve a specific value by name.\n  def get(param)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/nameservice.rb#L164-L200","documentation":"Raised by the Puppet nameservice provider family (useradd/groupadd/pw and friends, lib/puppet/provider/nameservice.rb:182) when the system deletion command returned by deletecmd (e.g. userdel, groupdel) exits non-zero while removing an existing object. The provider first checks exists? and returns early with 'already absent' if the object is gone, so this error means the object exists but the OS refused to delete it. The original Puppet::ExecutionFailure text (stderr/stdout of the command) is interpolated as %{detail} and the original backtrace is chained.","triggerScenarios":"Applying ensure => absent (or running `puppet resource user <name> ensure=absent`) for a user/group whose deletecmd fails: userdel reports 'user <name> is currently used by process N' or 'user <name> is currently logged in', groupdel reports 'group still has members', the command binary is missing from PATH, or @custom_environment breaks the execution.","commonSituations":"Deleting a service account while its processes are still running; trying to delete a group that still has users in /etc/group; LDAP/NSS-backed passwd entries that the local tool cannot remove; hardened systems where PATH is restricted via custom_environment.","solutions":["Read %{detail} in the message: it contains the exact userdel/groupdel stderr. Reproduce by running the same deletecmd manually as the same user (e.g. `sudo userdel <name>`).","If the detail says the user is logged in or has running processes, terminate them (`pgrep -u <name>`, log out sessions, stop the service) before re-applying, or consciously use a force flag via a manual Exec if appropriate.","For 'still has members' from groupdel, remove the members (or their primary group) first.","Verify the provider's commands exist on the node (confine/os check) and that custom_environment does not strip PATH."],"exampleFix":"# before: fails with 'user jboss is currently used by process 1234'\nuser { 'jboss': ensure => absent }\n\n# after: stop the service first so the account is no longer in use\nservice { 'jboss': ensure => stopped, before => User['jboss'] }\nuser { 'jboss': ensure => absent }","handlingStrategy":"try-catch","validationCode":"# pre-check that the object can actually be deleted\nname = 'jboss'\nif Etc.getpwnam(name) rescue nil\n  busy = `pgrep -u #{name}`.strip.length > 0\n  warn \"#{name} still has processes; delete will fail\" if busy\nend","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Type.type(:user).instances.each { |u| u.provider.flush if u.provider.respond_to?(:delete) }\nrescue Puppet::Error => e\n  raise unless e.message.start_with?('Could not delete')\n  # keep catalog application going, report which object failed\n  Puppet.err(\"delete skipped: #{e.message}\")\nend","preventionTips":["Order service stop / process termination (before =>) ahead of ensure => absent user/group resources.","Never delete groups while members reference them; clean memberships first.","Monitor %{detail} in agent logs — userdel stderr pinpoints the blocker immediately."],"tags":["puppet","nameservice","user-management","command-execution"],"backgroundTag":"command-execution-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}