CentOS 7 currently uses yum as its default package manager. However,
Fedora has moved to dnf for several releases and it provides significant
performance benefits. It can make the metadata cache, evaluate dependencies,
and handle fastest mirror checks much more efficiently.

The dnf and yum package managers can co-exist together without causing
conflicts. Several Fedora releases ran both of these simultaneously. The
dnf packages are available in the EPEL repositories (which we currently
enable). It uses all of the existing yum repositories and GPG keys as well.

The CentOS gate jobs are notoriously slow and the integrated gate times out on
tempest runs frequently. The longest running tasks in each role involve the
installation of distro packages because these tasks use state:latest the
yum tasks.

When Ansible sees state:latest, it goes through a fairly tedious process:

Run check-update, which checks the entire system for updates.

If some packages are returned (they need updates), Ansible searches the list
to see if any packages from the yum task are in that list.

If some packages need updates, Ansible calls yum to install those
packages.

This process can take 5-8 seconds even for one package. In comparison,
dnf completes the task in 0.8-1.6 seconds. This should give us some wiggle
room to get CI jobs completed sooner and convert more of the CentOS jobs from
non-voting to voting.

On CentOS systems, we should install dnf and python-dnf (for Ansible
compatibility). Ansible will prefer dnf over yum, so we would need to
ensure that each role has support for dnf tasks. Since both package
managers are interchangeable, this could be done by symlinking the
*_install_dnf.yml task files to *_install_yum.yml and using the
package module in those task files.

If dnf isn’t preferred, we could avoid using state:latest for CentOS
installations. This would cause CentOS deployments to diverge from Ubuntu
and OpenSUSE deployments and it would make bug triage more challenging.

Another option is to update the entire system when state:latest is
provided but switch all of the package installation tasks to use state:present. This will save us a small amount of time since Ansible will skip the
check-update step and go straight into updating all packages. This would
be another diversion from the Ubuntu/OpenSUSE process, however.

Developers must be aware that dnf is present on CentOS systems and that
Ansible will prefer it over yum. Any new roles/playbooks or updates to
existing ones will need to include support for dnf via the dnf module
or the package module (which selects dnf over yum already).

This work will require some release notes to notify developers and deployers of
the dnf change. However, there’s no need for extensive documentation since
dnf supports the same configurations and arguments as yum.