Open Source Development

 View Only

 Dnf install issue using ansible.builtin.dnf module

NBG UnixSystemsSupport's profile image
NBG UnixSystemsSupport posted Tue January 20, 2026 03:05 AM

Hello, when using module ansible.builtin.dnf we try to install packages such as the following on either AIX 7.2 that already have dnf toolbox installed.

Install packages with dnf module from variable PACKAGES (tmux,screen,wget,curl,libssh2,ncat,vim-enhanced,python3-dnf,python3.12)

{
  "results": [],
  "msg": "Could not import the dnf python module using /opt/freeware/bin/python3 (3.12.12 (main, Oct 14 2025, 02:05:51) [GCC 10.3.0]). Please install `python3-dnf` or `python2-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted ['/usr/libexec/platform-python', '/usr/bin/python3', '/usr/bin/python2', '/usr/bin/python'])",
  "invocation": {
    "module_args": {
      "conf_file": "/opt/freeware/etc/dnf/dnf.conf",
      "name": [
        "tmux",
        "screen",
        "wget",
        "curl",
        "libssh2",
        "ncat",
        "vim-enhanced",
        "python3-dnf",
        "python3.12"
      ],
      "state": "latest",
      "allow_downgrade": false,
      "autoremove": false,
      "bugfix": false,
      "cacheonly": false,
      "disable_gpg_check": false,
      "disable_plugin": [],
      "disablerepo": [],
      "download_only": false,
      "enable_plugin": [],
      "enablerepo": [],
      "exclude": [],
      "installroot": "/",
      "install_repoquery": true,
      "install_weak_deps": true,
      "security": false,
      "skip_broken": false,
      "update_cache": false,
      "update_only": false,
      "validate_certs": true,
      "sslverify": true,
      "lock_timeout": 30,
      "allowerasing": false,
      "nobest": false,
      "use_backend": "auto",
      "disable_excludes": null,
      "download_dir": null,
      "list": null,
      "releasever": null
    }
  },
  "_ansible_no_log": false,
  "changed": false
}

root@IFRSAPPDEV / # rpm -qa | grep dnf
libdnf-0.74.0-32_50.ppc
dnf-data-4.23.0-32_51.ppc
python3-dnf-4.23.0-32_51.ppc
dnf-automatic-4.23.0-32_51.ppc
python3.12-libdnf-0.74.0-32_50.ppc
python3-libdnf-0.74.0-32_50.ppc
python3.12-dnf-4.23.0-32_51.ppc
dnf-4.23.0-32_51.ppc


root@IFRSAPPDEV / # /opt/freeware/bin/dnf info python3-dnf
Last metadata expiration check: 4:25:35 ago on January 19, 2026 at 11:25:27 AM EET.
Installed Packages
Name         : python3-dnf
Version      : 4.23.0
Release      : 32_51
Architecture : ppc
Size         : 2.0 k
Source       : dnf-4.23.0-32_51.src.rpm
Repository   : @System
From repo    : AIX_Toolbox_72
Summary      : Meta package for Python 3 interface to DNF
URL          : https://github.com/rpm-software-management/dnf
License      : GPLv2+ and GPLv2 and GPL
Description  : Meta package for Python 3 interface to DNF.

the yaml that we use:

#---
#- name: Install packages from PACKAGES var
#  hosts: all
#  gather_facts: true
#  become: yes
#  vars:
#    ansible_python_interpreter: /opt/freeware/bin/python3
#  environment:
#    PACKAGES: "tmux,screen,wget,curl,ncat,vim-enhanced,python3-dnf,python3.11"
#  tasks:
    - name: "Install packages with dnf"
      block:
        - name: "Install packages with dnf module from variable PACKAGES ({{ PACKAGES }})"
          ansible.builtin.dnf:
            conf_file: /opt/freeware/etc/dnf/dnf.conf
            name: "{{ PACKAGES }}"
            state: latest
            use_backend: "{{ansible_pkg_mgr}}"
          vars:
            ansible_python_interpreter: "{{ '/opt/freeware/bin/python3' if ansible_distribution_version == '7.3' else '/opt/freeware/libexec/python3.12_32' }}"
      rescue:
        - name: "Rescue Install packages with shell from variable PACKAGES ({{ PACKAGES }})"
          ansible.builtin.shell:
            cmd: "{{dnf}} install -y {{ PACKAGES | replace(',',' ') }}"

Steve Munday's profile image
Steve Munday IBM Champion

Team:

Hi, good day to you.

A couple of things:

  • Does https://community.ibm.com/community/user/discussion/ansible-could-not-import-the-dnf-python-module-using-usrbinpython39 help at all?
  • Are you using 32_ or 64_ bit python (this is talked about in the link immediately above)?

All the best, Steve

NBG UnixSystemsSupport's profile image
NBG UnixSystemsSupport

well we use the 32bit version due to the fact that this is AIX 7.2

/opt/freeware/libexec/python3.12_32

Steve Munday's profile image
Steve Munday IBM Champion

Hi, in the initial post you state the following:

  "msg": "Could not import the dnf python module using /opt/freeware/bin/python3 (3.12.12 (main, Oct 14 2025, 02:05:51) [GCC 10.3.0]). Please install `python3-dnf` or `python2-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted ['/usr/libexec/platform-python', '/usr/bin/python3', '/usr/bin/python2', '/usr/bin/python'])",

The reference to python in "msg" is

Could not import the dnf python module using /opt/freeware/bin/python3

so wondering if this is where the issue lies as you're running with the 32-bit version of python (/opt/freeware/libexec/python3.12_32)?

Regards, Steve

NBG UnixSystemsSupport's profile image
NBG UnixSystemsSupport

Hello,

yes on purpose we use 32bit for the AIX 7.2 LPARs. isnt that meant to be the default?

root@IFRSAPPDEV / # ll /opt/freeware/libexec/python3
lrwxrwxrwx-    1 root     system           13 Nov 12 01:22PM /opt/freeware/libexec/python3 -> python3.12_32

Ayappan P's profile image
Ayappan P

You have to re-check your ansible playbook, as the error log is clearly mentioning it is using /opt/freeware/bin/python3 and not /opt/freeware/libexec/python3.12_32