ansible-lint to JUnit converter.
Project description
ansible-lint2junit
Converts ansible-lint output into JUnit XML, so lint findings show up as test results in CI — in particular in GitLab's test report UI.
This is a fork of wasilak/ansible-lint-junit (MIT licensed), renamed and modernised for Python 3.13+ and GitLab:
- Testcases carry a stable identity (
classname= ansible-lint rule ID,name=file:line message), so GitLab can track newly-failed/resolved findings between pipeline runs. - Testcases carry a
fileattribute, so GitLab links each finding to the source file. - Suite
tests/failurescounts reflect the actual findings (summary lines and blanks are ignored). - No longer depends on
ansible-lintitself — only its text output — so it installs cleanly alongside any ansible-lint version (the only dependency isdefusedxml).
Installation
From this project's GitLab package registry:
pip install ansible-lint2junit --index-url https://gitlab.surrey.ac.uk/api/v4/projects/sm0049%2Fansible-lint2junit/packages/pypi/simple
Usage
Pipe ansible-lint -p output in:
ansible-lint playbook.yml -p --nocolor | ansible-lint2junit -o ansible-lint.xml
or go via a file (multiple input files are concatenated):
ansible-lint -p --nocolor playbook.yml > ansible-lint.txt
ansible-lint2junit ansible-lint.txt -o ansible-lint.xml
Options:
| Option | Description |
|---|---|
-o FILE |
output file (default ansible-lint2junit.xml) |
-v |
also print the XML to stdout |
-d |
emit a single dummy testcase when there are no findings, for CI parsers that reject empty suites |
--version |
print version |
GitLab CI example
ansible-lint:
image: python:3.13
script:
- pip install ansible-lint
- pip install ansible-lint2junit --index-url https://gitlab.surrey.ac.uk/api/v4/projects/sm0049%2Fansible-lint2junit/packages/pypi/simple
- ansible-lint -p --nocolor . > ansible-lint.txt || true
- ansible-lint2junit ansible-lint.txt -o ansible-lint.xml
- "! grep -q '<failure' ansible-lint.xml"
artifacts:
when: always
reports:
junit: ansible-lint.xml
The || true keeps the job running so the report is always generated; the final grep
fails the job when there are findings, after the report exists. Drop it if lint findings
should not fail the pipeline.
Output
- Findings become JUnit
<failure>testcases, grouped by ansible-lint rule. - Clean input still produces a valid (empty) JUnit XML file, so JUnit parsers that
fail on a missing report (e.g. Bamboo) keep working. Use
-dfor parsers that also reject suites with zero tests. - Both modern ansible-lint (
rule-id[subrule] message) and legacy ([E301] message) output formats are recognised; unrecognised lines that still look likefile:line: messageare kept with a genericansible-lintclassname.
Development
pip install -e .[test]
pytest
License
Distributed under the MIT license, as is the original project by Piotr Boruc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ansible_lint2junit-1.0.0.tar.gz.
File metadata
- Download URL: ansible_lint2junit-1.0.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c2458da40e141face610ce88a3e7d0f81f53ba70c9fcbe9fed9f90173f01168
|
|
| MD5 |
75a52e6428368ff3fec141b3e1cb939b
|
|
| BLAKE2b-256 |
d1f81ebf1cac5d547063e1f60bcd8244faa949c5b234f6e7dc837ac985e6388b
|
File details
Details for the file ansible_lint2junit-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ansible_lint2junit-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94af6fd71a5a0119d2c243f0d005ae2e64f506bcba31988fc7b75a8c09027346
|
|
| MD5 |
c01b6b2e087a5008d642ef03bf650a7e
|
|
| BLAKE2b-256 |
13ac517ad2a6f91def0fcf1dd805f5c515bd262b0449a073930022e3909f1f92
|