Skip to main content

Ansible collection carlijoy.compat — backport of ansible.builtin.dnf for EL8 + ansible-core >= 2.17 via /usr/libexec/platform-python

Project description

ansible-el-compat

Ansible collection carlijoy.compat — backport of ansible.builtin modules for EL8 + ansible-core >= 2.17.

The problem

ansible-core >= 2.17 ships module code that uses from __future__ import annotations, requiring Python 3.10+ on managed hosts. On AlmaLinux / Rocky Linux / RHEL 8, python3-dnf is only available for Python 3.6 and 3.9 — so ansible.builtin.dnf fails with a modern ansible-core.

The solution

This collection backports ansible.builtin.dnf to EL8 by shipping a pre-built binary module that is the original ansible.builtin.dnf from ansible-core 2.15 (the last release that fully supported EL8), bundled together with all of its ansible.module_utils.* dependencies into a self-executing zip archive.

The bundle carries a #!/usr/libexec/platform-python shebang. Ansible detects it as a binary module, copies it to the managed host, and runs it directly — without the ansiballz wrapper — under /usr/libexec/platform-python, the EL8 system Python that has python3-dnf available. The result is 100% feature parity with ansible.builtin.dnf on EL8 targets, regardless of which Python interpreter drives ansible-core on the controller.

The bundle is regenerated by build-script/build_dnf_bundle.py (uses uv run with ansible-core 2.15 pinned via inline script metadata).

Installation

via pip / uv (recommended)

pip install ansible-el-compat
# or
uv pip install ansible-el-compat

No ansible-galaxy required — the collection is discovered automatically from site-packages/ansible_collections/.

via ansible-galaxy

ansible-galaxy collection install carlijoy.compat

Modules

carlijoy.compat.dnf

Backport of ansible.builtin.dnf for EL8. Accepts the same parameters as ansible.builtin.dnf — it is that module, just packaged to run under the right Python interpreter.

Common options

Option Type Default Description
name str or list required Package name(s), version constraints supported
state str present present, absent, or latest
enablerepo list [] Repos to enable for this transaction only
disablerepo list [] Repos to disable for this transaction only
disable_gpg_check bool false Pass --nogpgcheck to dnf
update_cache bool false Run dnf makecache before the transaction

Examples

- name: Install a package
  carlijoy.compat.dnf:
    name: htop
    state: present

- name: Install multiple packages
  carlijoy.compat.dnf:
    name:
      - htop
      - curl
    state: present

- name: Remove a package
  carlijoy.compat.dnf:
    name: telnet
    state: absent

- name: Install from a specific repo only
  carlijoy.compat.dnf:
    name: rabbitmq-server <= 4
    disablerepo: '*'
    enablerepo: rabbitmq
    state: present

- name: Upgrade, refreshing cache first
  carlijoy.compat.dnf:
    name: openssl
    state: latest
    update_cache: true

Migrating from ansible.builtin.dnf

# Before
- ansible.builtin.dnf:
    name: httpd
    state: present

# After
- carlijoy.compat.dnf:
    name: httpd
    state: present

For persistent repo enable/disable (not per-transaction), continue using community.general.dnf_config_manager.

Development

git clone https://github.com/CarliJoy/ansible-el-compat
cd ansible-el-compat
uv sync --group dev
uv run prek install          # install git hooks
uv run prek run --all-files  # lint + type check
uv run pytest tests/ -v      # integration tests (requires Docker)

Tests use testcontainers to spin up a real AlmaLinux 8 container with SSH and Python 3.12, then run Ansible against it. Docker must be available on the test host.

Rebuilding the backported bundle

uv run build-script/build_dnf_bundle.py

This downloads ansible-core 2.15 into an isolated environment (via the inline uv script metadata), extracts ansible/modules/dnf.py and all transitive ansible/module_utils/ dependencies, and writes the self-executing zip to src/ansible_collections/carlijoy/compat/plugins/modules/dnf.

License

GPL-3.0-or-later

The backported module bundle contains code from ansible-core, which is licensed under the GNU General Public License v3.0 or later. This collection is therefore also distributed under GPL-3.0-or-later.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansible_el_compat-0.1.1.tar.gz (243.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ansible_el_compat-0.1.1-py3-none-any.whl (139.3 kB view details)

Uploaded Python 3

File details

Details for the file ansible_el_compat-0.1.1.tar.gz.

File metadata

  • Download URL: ansible_el_compat-0.1.1.tar.gz
  • Upload date:
  • Size: 243.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ansible_el_compat-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d578646c5afa2432ebba859da987d8da10a77259e4342b246b26fe3dc5a073b
MD5 46a2295e3825aa2ea12b1f6f91ad60b2
BLAKE2b-256 71f0e3af4f7afcd7c4d87653ef865bd7fdec551e22305c31e8b5618251f86530

See more details on using hashes here.

File details

Details for the file ansible_el_compat-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ansible_el_compat-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 139.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ansible_el_compat-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20f08d82d62c117bc6c31b8b083066ec33f1a306925020aef3c8086638ff1962
MD5 c419521124c23f7355e175352da67b04
BLAKE2b-256 abda8ab07ce7c4d857a524d654173d1d8e3362c57b8054fdbb365f00f86beb7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page