Ansible Compat is a Python library providing essential compatibility layers and utilities for Ansible projects, primarily benefiting Ansible collection developers. It helps in managing forward and backward compatibility across different Ansible core versions by abstracting away API differences and simplifying interactions with Ansible's runtime. The current version is 26.3.0, and releases are typically aligned with major Ansible core updates or significant feature enhancements.
pip install ansible-compatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `AnsibleCompatConfig` and `AnsibleRuntime` to access Ansible's configuration and runtime environment. It shows how to query the Ansible version, configuration file path, collection paths, and find a specific collection. It also includes an example of using the `AnsiblePath` primitive.
Migrate to using public methods of the `AnsibleRuntime` class for robust path resolution and interaction with Ansible's loading mechanisms.
Always ensure your Python environment meets the minimum version specified in the `ansible-compat` project's `pyproject.toml` or documentation, as well as the requirements of the `ansible-core` version you intend to use.
Refer to the `ansible-compat` documentation or its `pyproject.toml` for the supported range of `ansible-core` versions and install a compatible `ansible-core` release.
Explicitly pass relevant configuration paths or set standard Ansible environment variables (e.g., `ANSIBLE_CONFIG`, `ANSIBLE_COLLECTIONS_PATH`) before initializing `AnsibleCompatConfig` or `AnsibleRuntime` to ensure proper discovery.