ansible.builtin.dnf module – Manages packages with the dnf package manager
Note
This module is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
module name
dnf
even without specifying the collections:
keyword.
However, we recommend you use the FQCN for easy linking to the
module documentation and to avoid conflicting with other collections that may have
the same module name.
New in version 1.9: of ansible.builtin
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.6
python-dnf
for the autoremove option you need dnf >= 2.0.1”
Parameters
Parameter |
Comments |
---|---|
Specify if the named package and version is allowed to downgrade a maybe already installed higher version of that package. Note that setting allow_downgrade=True can make this module behave in a non-idempotent way. The task could end up with a set of packages that does not match the complete list of specified packages to install (because dependencies between the downgraded package and others can cause changes to the packages which were in the earlier transaction). Choices:
|
|
If Choices:
|
|
If Choices:
|
|
If set to Note that, similar to Choices:
|
|
Tells dnf to run entirely from system cache; does not download or update metadata. Choices:
|
|
The remote dnf configuration file to use for the transaction. |
|
Disable the excludes defined in DNF config files. If set to If set to If set to |
|
Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if state is present or latest. This setting affects packages installed from a repository as well as “local” packages installed from the filesystem or a URL. Choices:
|
|
Plugin name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction. |
|
Repoid of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a “,”. |
|
Specifies an alternate directory to store packages. Has an effect only if download_only is specified. |
|
Only download the packages, do not install them. Choices:
|
|
Plugin name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. |
|
Repoid of repositories to enable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a “,”. |
|
Package name(s) to exclude when state=present, or latest. This can be a list or a comma separated string. |
|
This is effectively a no-op in DNF as it is not needed with DNF, but is an accepted parameter for feature parity/compatibility with the yum module. Choices:
|
|
Will also install all packages linked by a weak dependency relation. Choices:
|
|
Specifies an alternative installroot, relative to which all packages will be installed. Default: “/” |
|
Various (non-idempotent) commands for usage with |
|
Amount of time to wait for the dnf lockfile to be freed. Default: 30 |
|
A package name or package specifier with version, like Comparison operators for package version are valid here You can also pass an absolute path for a binary which is provided by the package to install. See examples for more information. |
|
Set best option to False, so that transactions are not limited to best candidates only. Choices:
|
|
Specifies an alternative release from which all packages will be installed. |
|
If set to Note that, similar to Choices:
|
|
Skip all unavailable packages or packages with broken dependencies without raising an error. Equivalent to passing the –skip-broken option. Choices:
|
|
Whether to install ( Default is Choices:
|
|
Force dnf to check if cache is out of date and redownload if needed. Has an effect only if state is present or latest. Choices:
|
|
When using latest, only update installed packages. Do not install packages. Has an effect only if state is latest Choices:
|
|
This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to This should only set to Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: partial In the case of dnf, it has 2 action plugins that use it under the hood, ansible.builtin.yum and ansible.builtin.package. |
Indicates this has a corresponding action plugin so some parts of the options can be executed on the controller |
|
Support: none |
Supports being used with the |
|
Support: none |
Forces a ‘global’ task that does not execute per host, this bypasses per host templating and serial, throttle and other loop considerations Conditionals will work as if This action will not work normally outside of lockstep strategies |
|
Support: full |
Can run in check_mode and return changed status prediction withought modifying target |
|
Support: full |
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode |
|
Platform: rhel |
Target OS/families that can be operated against |
Notes
Note
When used with a
loop:
each package will be processed individually, it is much more efficient to pass the list directly to the name option.Group removal doesn’t work if the group was installed with Ansible because upstream dnf’s API doesn’t properly mark groups as installed, therefore upon removal the module is unable to detect that the group is installed (https://bugzilla.redhat.com/show_bug.cgi?id=1620324)
Examples
- name: Install the latest version of Apache
dnf:
name: httpd
state: latest
- name: Install Apache >= 2.4
dnf:
name: httpd>=2.4
state: present
- name: Install the latest version of Apache and MariaDB
dnf:
name:
- httpd
- mariadb-server
state: latest
- name: Remove the Apache package
dnf:
name: httpd
state: absent
- name: Install the latest version of Apache from the testing repo
dnf:
name: httpd
enablerepo: testing
state: present
- name: Upgrade all packages
dnf:
name: "*"
state: latest
- name: Install the nginx rpm from a remote repo
dnf:
name: 'http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm'
state: present
- name: Install nginx rpm from a local file
dnf:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present
- name: Install Package based upon the file it provides
dnf:
name: /usr/bin/cowsay
state: present
- name: Install the 'Development tools' package group
dnf:
name: '@Development tools'
state: present
- name: Autoremove unneeded packages installed as dependencies
dnf:
autoremove: yes
- name: Uninstall httpd but keep its dependencies
dnf:
name: httpd
state: absent
autoremove: no
- name: Install a modularity appstream with defined stream and profile
dnf:
name: '@postgresql:9.6/client'
state: present
- name: Install a modularity appstream with defined stream
dnf:
name: '@postgresql:9.6'
state: present
- name: Install a modularity appstream with defined profile
dnf:
name: '@postgresql/client'
state: present
Authors
Igor Gnatenko (@ignatenkobrain)
Cristian van Ee (@DJMuggs) <cristian at cvee.org>
Berend De Schouwer (@berenddeschouwer)
Adam Miller (@maxamillion)