ansible.builtin.dnf – Manages packages with the dnf package manager¶
Note
This module is part of ansible-base
and included in all Ansible
installations. In most cases, you can use the short module name
dnf even without specifying the collections:
keyword.
Despite that, 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¶
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 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 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) <i.gnatenko.brain@gmail.com>
Cristian van Ee (@DJMuggs) <cristian at cvee.org>
Berend De Schouwer (@berenddeschouwer)
Adam Miller (@maxamillion) <admiller@redhat.com>