# Ansible when logic to determine whether to use yum or dnf to install packages on ansible\_os\_family='RedHat'

**URL:** <https://forum.ansible.com/t/ansible-when-logic-to-determine-whether-to-use-yum-or-dnf-to-install-packages-on-ansible-os-family-redhat/32260>\
**Category:** Ansible Project\
**Created:** [February 18, 2020, 9:25am UTC](https://forum.ansible.com/t/ansible-when-logic-to-determine-whether-to-use-yum-or-dnf-to-install-packages-on-ansible-os-family-redhat/32260 "2020-02-18T09:25:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donald\_Jones](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@Donald\_Jones](https://forum.ansible.com/u/Donald_Jones)\
**Post date:** [February 18, 2020, 9:25am UTC](https://forum.ansible.com/t/ansible-when-logic-to-determine-whether-to-use-yum-or-dnf-to-install-packages-on-ansible-os-family-redhat/32260/1 "2020-02-18T09:25:18Z")

</div>

Hi,

Up until now I’ve been making a logic decision with my ansible roles based upon the ansible\_os\_family, to run the appropriate module for yum (‘RedHat’) or apt (‘Debian’).

With the introduction of CentOS 8, dnf has been brought in as a replacement for yum.  
So my question is, is there a prefered ‘when’ logic that I can use to determine whether I should use the dnf or yum module in a playbook/role? Ideally something that maximises future proof.

Regards

Donald

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 18, 2020, 10:29am UTC](https://forum.ansible.com/t/ansible-when-logic-to-determine-whether-to-use-yum-or-dnf-to-install-packages-on-ansible-os-family-redhat/32260/2 "2020-02-18T10:29:59Z")

</div>

It's possible to use "package – Generic OS package manager". The selection of  
the package manager is automatic by default.  
[https://docs.ansible.com/ansible/latest/modules/package\_module.html](https://docs.ansible.com/ansible/latest/modules/package_module.html)

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Martin\_Krizek](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@Martin\_Krizek](https://forum.ansible.com/u/Martin_Krizek)\
**Post date:** [February 18, 2020, 10:34am UTC](https://forum.ansible.com/t/ansible-when-logic-to-determine-whether-to-use-yum-or-dnf-to-install-packages-on-ansible-os-family-redhat/32260/3 "2020-02-18T10:34:19Z")

</div>

> \> Up until now I've been making a logic decision with my ansible roles based  
> \> upon the ansible\_os\_family, to run the appropriate module for yum  
> \> ('RedHat') or apt ('Debian').

You can use `ansible_pkg_mgr` variable instead.

M.

---

<div class="post-metadata">

**Author:** ![Donald\_Jones](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@Donald\_Jones](https://forum.ansible.com/u/Donald_Jones)\
**Post date:** [February 18, 2020, 2:51pm UTC](https://forum.ansible.com/t/ansible-when-logic-to-determine-whether-to-use-yum-or-dnf-to-install-packages-on-ansible-os-family-redhat/32260/4 "2020-02-18T14:51:11Z")

</div>

Thanks. That looks like a good option:

[https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing\_packages/](https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/installing_packages/)

I think that it comes down to:

- continue using apt for Debian systems (due to field changes)
- use {ansible\_pkg\_mgr} for RedHat / Fedora systems (as their parameters are mostly aligned)
