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

14 views
Skip to first unread message

Donald Jones

unread,
Feb 18, 2020, 4:25:18 AM2/18/20
to Ansible Project
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



Vladimir Botka

unread,
Feb 18, 2020, 5:30:15 AM2/18/20
to Donald Jones, ansible...@googlegroups.com
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

Martin Krizek

unread,
Feb 18, 2020, 5:34:54 AM2/18/20
to ansible...@googlegroups.com
On Tue, Feb 18, 2020 at 11:30 AM Vladimir Botka <vbo...@gmail.com> wrote:
>
> On Tue, 18 Feb 2020 01:25:18 -0800 (PST)
> Donald Jones <donald.st...@gmail.com> wrote:
>
> > 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.

Donald Jones

unread,
Feb 18, 2020, 9:51:11 AM2/18/20
to Ansible Project
Thanks. That looks like a good option:

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)

Reply all
Reply to author
Forward
0 new messages