dnf – Manages packages with the dnf package manager¶
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
Status¶
- This module is guaranteed to have backward compatible interface changes going forward. [stableinterface]
- This module is maintained by the Ansible Core Team. [core]
Red Hat Support¶
More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.
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>
Hint
If you notice any issues in this documentation, you can edit this document to improve it.
