# Why does dnf state: absent remove packages depending on the package too?

**URL:** <https://forum.ansible.com/t/why-does-dnf-state-absent-remove-packages-depending-on-the-package-too/44764>\
**Category:** Get Help\
**Tags:** bug, playbook, ansible, dnf, ansible-core\
**Created:** [October 30, 2025, 12:58pm UTC](https://forum.ansible.com/t/why-does-dnf-state-absent-remove-packages-depending-on-the-package-too/44764 "2025-10-30T12:58:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![firefly-sudo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/firefly-sudo/32/9737_2.png) [@firefly-sudo](https://forum.ansible.com/u/firefly-sudo)\
**Post date:** [October 30, 2025, 12:58pm UTC](https://forum.ansible.com/t/why-does-dnf-state-absent-remove-packages-depending-on-the-package-too/44764/1 "2025-10-30T12:58:27Z")

</div>

Using this task, I want to remove the patch package from my servers.  
But after running the task, dkms is also uninstalled. Dkms depends on the patch package.

```auto
  - name: "Remove now unused patch package"
    ansible.builtin.dnf:
      name: patch
      state: absent
      allowerasing: false

```

The behaviour I would expect is that the task fails, stating a package depends on it, and unless that package is also explicitly mentioned in that task, it wont continue.  
Instead it just removes the dkms package too. Why is that?

i tried adding allowerasing = false, even thought that should be enabled by default, and as expected it didnt change anything.

I found a [stack overflow post](https://stackoverflow.com/questions/77133830/ansible-remove-packages-not-marked-as-explicitly-installed-now-or-previously) stating similar behaviour even two years ago.

I tried installing patch explicitly, installing dkms explicitly, running the playbook and again both packages are gone.

Anyone can help me out why this happens? Is this intended behaviour, if so, why?

Thanks a lot in advance, I’m just confused why it works like that.

Im running ansible version core 2.18.2, python version 3.12.5

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [October 30, 2025, 2:19pm UTC](https://forum.ansible.com/t/why-does-dnf-state-absent-remove-packages-depending-on-the-package-too/44764/2 "2025-10-30T14:19:23Z")

</div>

Because that’s how `dnf` works. To remove a package, it also has to remove packages that depend on that package.

```console
vereveel-root ~ # dnf remove patch
Dependencies resolved.
================================================================================
 Package Arch Version Repository Size
================================================================================
Removing:
 patch x86_64 2.7.6-16.el9 @appstream 259 k
Removing dependent packages:
 rpm-build x86_64 4.16.1.3-37.el9 @appstream 146 k
 rpmdevtools noarch 9.5-1.el9 @appstream 195 k

```
