ansibleansible-lint

ansible-lint: Is there a way to ignore errors in all files, without specifying file names?


I work in a large ansible repository without linting, and I would like to add linting. Usually I would add a linter, run it, note all current errors and warnings, add them to an ignore-file and then commit that to the repository. This way, all old sins are allowed for now, but any new error will get reported. I can then pick the ignored rules one by one and address them, and remove them from the ignore file (or leave them in if we decide that we want it that way).

With ansible-lint, however, I am unable to find a way of doing this. There is the .ansible-lint-ignore file, but with that I only seem able to ignore on a filename basis and not for all files? I don't want to add all current errors for all files in the entire repository to this file if possible. And adding just the current errors for the current files will not ignore the same errors being made in new files, so to speak.

Is there any way of doing this? If not, how do you all adopt working with ansible-lint in an effective way?


Solution

  • Yes, you're right that .ansible-lint-ignore works on a per-file basis, which makes it tricky to ignore all existing errors across the whole repository while enforcing new ones.

    A workaround is to run ansible-lint and output the current issues to a baseline file. Then, use a pre-commit hook or a CI check that runs ansible-lint and filters out the known issues.

    Here’s a simple approach:

    1. Run ansible-lint and save the current issues

      sh
      

      CopyEdit

      ansible-lint > ansible-lint-baseline.txt

    2. Use grep or a script in CI to only report new issues
      In your CI pipeline or local pre-commit hook, compare new lint results against ansible-lint-baseline.txt and fail only if there are new issues.

    3. Gradually fix and remove ignored rules
      As you fix issues, update or remove entries from ansible-lint-baseline.txt to ensure progress.

    This method keeps the repo clean moving forward without overwhelming you with fixing all old issues at once. Hope this helps!