Update packages with DNF and name wildcard

I tried to upgrade some packages with the APT/DNF modules.

To do this, I’ve set a variable with the package name and a wildcard.
For example, let’s consider upgrading all python3 packages with DNF.

# Task
vars:
  package: "python3*"

tasks:
  - name: Update packages using DNF
    ansible.builtin.dnf:
      name: "{{ package }}"
      state: latest
      update_cache: yes
      update_only: true

This way the python3 packages won’t be upgraded because there’s no python3*.

# Result
msg: Nothing to do
  rc: 0
  results:
  - Packages providing python3* not installed due to update_only specified

Unlike the APT module, the DNF module does not seems to support wildcards. Its documentation says I could use a list for this, but I would need to know and write all packages names.

Is there a way to use a wildcard or, maybe, a regular expression with the DNF module?

4 Likes

Looks like (according to the documentation) you can only use “*” to upgrade all packages.

Another idea: use the ansible.builtin.package_facts module, loop over the result and only grab matching packages for upgrading with the ansible.builtin.dnf module. This way you can apply your pattern, or regex.

6 Likes

Hi @markfree! It looks like the post might be solved - could you check to see if the response by @ads worked for you?

If so, it would be super helpful if you could click the :heavy_check_mark: on their post to accept the solution - it recognises the input of others, helps our volunteers find new issues to answer, and keeps the forum nice and tidy.

Thanks!
(this is template reply, do feel free to reply if I’ve misunderstood the situation!)

2 Likes