Skip to main content

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 GitLab (Python 3.9+):

  • 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 file attribute, so GitLab links each finding to the source file.
  • Suite tests/failures counts reflect the actual findings (summary lines and blanks are ignored).
  • No longer depends on ansible-lint itself — only its text output — so it installs cleanly alongside any ansible-lint version (the only dependency is defusedxml).
  • ANSI colour codes are stripped from the input, so forgetting --nocolor doesn't silently produce an empty report.
  • --fail-on-findings lets one CI step both publish the report and fail the job.

Installation

From PyPI:

pip install ansible-lint2junit

or 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); use -o - to write to stdout
-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
-f, --fail-on-findings exit with status 1 when there is at least one finding
--version print version

If the input is non-empty but no line matches the file:line: message format, a warning is printed to stderr — usually a sign the input wasn't produced with -p.

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 --fail-on-findings
  artifacts:
    when: always
    reports:
      junit: ansible-lint.xml

The || true keeps the job running so the report is always generated; --fail-on-findings then 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 -d for 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 like file:line: message are kept with a generic ansible-lint classname.

Development

pip install -e '.[test]'
pytest                  # tests (with coverage in CI)
ruff check . && ruff format --check .   # lint/format (pip install ruff)
mypy                    # type check (pip install mypy)

License

Distributed under the MIT license, as is the original project by Piotr Boruc.

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_lint2junit-1.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

ansible_lint2junit-1.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file ansible_lint2junit-1.1.0.tar.gz.

File metadata

  • Download URL: ansible_lint2junit-1.1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for ansible_lint2junit-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4d76c26d939a515b7ac538c8607a77164f1a2823938bd7cce37e2280b24a689d
MD5 572fec87b636133d40eb50065ae9738e
BLAKE2b-256 55f924a2b817b6d7722977d778eaf601504fb51c1a27aa959128e7f16c7d8c4a

See more details on using hashes here.

File details

Details for the file ansible_lint2junit-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_lint2junit-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19d1a3d4962f214f0cc4e4a12b846db3df617efc330a596ab489af8180b73963
MD5 bd3f04e80cfaa53cb0b4b1b7569985cb
BLAKE2b-256 3b806cfc44289630a4109882b4d7678083392cf7d1029c2db898b233d09bf93e

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