- Docs »
- dnf - Manages packages with the dnf package manager
-
You are reading an unmaintained version of the Ansible documentation. Unmaintained Ansible versions can contain unfixed security vulnerabilities (CVE). Please upgrade to a maintained version. See the latest Ansible documentation.
dnf - Manages packages with the dnf package manager
- Installs, upgrade, removes, and lists packages and groups with the dnf package manager.
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”
Parameter |
Choices/Defaults |
Comments |
autoremove
bool
(added in 2.4) |
|
If yes , removes all "leaf" packages from the system that were originally installed as dependencies of user-installed packages but which are no longer required by any such package. Should be used alone or when state is absent
|
conf_file
|
|
The remote dnf configuration file to use for the transaction.
|
disable_gpg_check
bool |
|
Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if state is present or latest.
|
disablerepo
|
|
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 ",".
|
enablerepo
|
|
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 ",".
|
installroot
(added in 2.3) |
Default:
"/"
|
Specifies an alternative installroot, relative to which all packages will be installed.
|
list
|
|
Various (non-idempotent) commands for usage with /usr/bin/ansible and not playbooks. See examples.
|
name
required |
|
A list of package names, or package specifier with version, like name-1.0 When using state=latest, this can be '*' which means run: dnf -y update. You can also pass a url or a local path to a rpm file.
|
releasever
(added in 2.6) |
Default:
null
|
Specifies an alternative release from which all packages will be installed.
|
state
|
Choices:
present ←
- latest
- absent
|
Whether to install (present , latest ), or remove (absent ) a package.
|
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.
- name: install the latest version of Apache
dnf:
name: httpd
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 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
This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.
This module is flagged as core which means that it is maintained by the Ansible Core Team. See Module Maintenance & Support for more info.
For a list of other modules that are also maintained by the Ansible Core Team, see here.
- “Igor Gnatenko (@ignatenkobrain)” <i.gnatenko.brain@gmail.com>
- “Cristian van Ee (@DJMuggs)” <cristian at cvee.org>
- Berend De Schouwer (github.com/berenddeschouwer)
Hint
If you notice any issues in this documentation you can edit this document to improve it.