tox-ansible is a utility designed to simplify the testing of Ansible content collections. Implemented as a tox plugin, it provides a streamlined way to test Ansible content across various Python interpreters and Ansible versions. It leverages tox for environment management, ansible-test sanity for sanity checks, and pytest for unit and integration tests. The current version is 26.3.0, and it follows a regular release cadence, often aligning with other Ansible development tools.
pip install tox-ansibleVerified import paths — ran on the pinned version, not inferred.
To get started, create an empty `tox-ansible.ini` file in the root of your Ansible collection. Then, list the dynamically generated Ansible testing environments using `tox list --ansible --conf tox-ansible.ini`. To run tests in a specific environment, like `sanity-py3.11-2.14`, execute `tox -e sanity-py3.11-2.14 --ansible --conf tox-ansible.ini`. You can also run all tests of a specific type (e.g., `unit`) across all available environments using `tox -f unit --ansible -p auto --conf tox-ansible.ini`.
Consult community resources and GitHub issues for clarification. Experiment with configurations carefully and incrementally.
Ensure that your testing environment's PYTHONPATH correctly includes the path to your Ansible collection, or investigate specific pytest-ansible configurations.
Minimize overrides where possible. If custom configurations are necessary, thoroughly test them against new Python and Ansible versions, especially when upgrading dependencies.
Use generic environment names like `py` for unit tests and rely on tox-ansible's dynamic environment generation for version matrix testing. For CI/CD, ensure the base Python interpreter is consistent or explicitly defined outside the tox `envlist`.
For integration tests requiring specific environments, consider using custom Docker images or more explicit environment definitions to ensure stability across container updates.