Ansible when logic to determine whether to use yum or dnf to install packages on ansible_os_family='RedHat'

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

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

HTH,

  -vlado

> 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.

Thanks. That looks like a good option:

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)