Plugins¶
In-house plugins live in plugins/{callback,filter,lookup,modules,module_utils}/.
- Start with the standard Linuxfabrik Python header (copy it from any in-house plugin), followed by
from __future__ import absolute_import, division, print_functionand__metaclass__ = type. - Modules start with
#!/usr/bin/pythoninstead of the header's#!/usr/bin/env python3. ansible-core applies interpreter discovery andansible_python_interpreteronly to a shebang whose interpreter is namedpython; it runs#!/usr/bin/env python3as it is, which fails on RHEL 8 hosts withoutpython3. Themodule-shebangpre-commit hook guards this. - Use single quotes and f-strings (vendored plugins keep their upstream style).
- Carry valid-YAML
DOCUMENTATION(andRETURN/EXAMPLESwhere applicable). Adescriptionbullet with a colon followed by a space becomes a mapping and breaksansible-doc; rephrase or quote it. Verify withansible-doc --type <callback|filter|lookup|module> linuxfabrik.lfops.<name>;tests/unit/test_plugin_docs.pyguards this. - Set
version_addedto the first release, never change it. module_utilsholds shared code. Do not import the Linuxfabrik Python Libraries (lib); copy what you need and note the origin.
Plugin Tests¶
Unit tests are mandatory for every in-house plugin; a pull request adding or changing a plugin adds or updates its test.
tests/unit/mirrors the plugin tree,test_<plugin>.py(e.g.tests/unit/plugins/filter/test_combine_lod.py). Plugins with collection-qualified imports are imported viaansible_collections.linuxfabrik.lfops..., whichtests/conftest.pymakes resolvable. Assert behavior, not implementation details.- Controller plugins (
callback/,filter/,lookup/) run on the controller's Python (>= 3.10). Managed-node plugins (modules/,module_utils/) must work down to Python 3.6 (RHEL 8); their tests also run in UBI 8 ([testenv:py36-target]), so test code must be valid Python 3.6 too. - Run with
tox,tox -e py311-ansible216,tox -f py311orpytest tests/unit, seetests/README.md. TheLinuxfabrik: Unit Testsworkflow runs both tiers on every push and pull request.