Introduction
The Ansible Lint sanity rule validates the ignore-x.x.txt files used in Ansible collections. These files define exemptions from sanity tests — but not all exemptions are allowed. This rule enforces that only approved ignores are used, maintaining code quality standards required for Red Hat Certification and Ansible Galaxy publishing.
The Rule
Rule name: sanity
Tags: idiom
Scope: Ansible collections (not standalone playbooks)
The rule checks tests/sanity/ignore-*.txt files in your collection to ensure:
- Only permitted ignores are used
- Ignore entries follow the correct format
Error Messages
sanity[cannot-ignore]
Triggered when an ignore entry uses a test that is not in the allowed list:
tests/sanity/ignore-2.17.txt:3: sanity[cannot-ignore]
Entry 'plugins/modules/mymod.py pep8' is not a permitted ignore.
Fix: Remove the ignore entry and fix the underlying issue instead.
sanity[bad-ignore]
Triggered when an ignore entry has incorrect formatting:
tests/sanity/ignore-2.17.txt:5: sanity[bad-ignore]
Entry has incorrect format.
Fix: Ensure each line follows the format:
path/to/file test-name
Allowed Ignores
The following ignores are permitted across all Ansible versions:
| Ignore | Purpose |
|---|---|
validate-modules:missing-gplv3-license | Module missing GPLv3 license header |
action-plugin-docs | Action plugin documentation |
import-2.6 / import-2.6!skip | Python 2.6 import compatibility |
import-2.7 / import-2.7!skip | Python 2.7 import compatibility |
import-3.5 / import-3.5!skip | Python 3.5 import compatibility |
compile-2.6 / compile-2.6!skip | Python 2.6 compilation compatibility |
compile-2.7 / compile-2.7!skip | Python 2.7 compilation compatibility |
compile-3.5 / compile-3.5!skip | Python 3.5 compilation compatibility |
shellcheck | Shell script linting |
shebang | Script shebang line |
pylint:used-before-assignment | Pylint false positive |
Anything not on this list will trigger sanity[cannot-ignore].
The ignore-x.x.txt File
Located at tests/sanity/ignore-X.Y.txt where X.Y is the ansible-core version:
# tests/sanity/ignore-2.17.txt
# Format: filepath test-name [optional-reason]
plugins/modules/legacy_module.py validate-modules:missing-gplv3-license
plugins/modules/old_module.py import-2.7!skip
plugins/module_utils/compat.py compile-2.7!skip
File Naming Convention
tests/sanity/ignore-2.15.txt # For ansible-core 2.15
tests/sanity/ignore-2.16.txt # For ansible-core 2.16
tests/sanity/ignore-2.17.txt # For ansible-core 2.17
Fixing Common Issues
Remove Unpermitted Ignores
# tests/sanity/ignore-2.17.txt
plugins/modules/mymod.py validate-modules:missing-gplv3-license
-plugins/modules/mymod.py pep8 # ← NOT ALLOWED — fix the pep8 issue instead
-plugins/modules/mymod.py pylint:no-name # ← NOT ALLOWED
Fix the Underlying Code Instead
Instead of ignoring pep8 errors:
# BEFORE — triggers pep8 error
def myFunction( arg1,arg2 ):
return arg1+arg2
# AFTER — fix the style issue
def my_function(arg1, arg2):
return arg1 + arg2
Fix Formatting Errors
# tests/sanity/ignore-2.17.txt
-plugins/modules/mymod.py validate-modules:missing-gplv3-license extra text
+plugins/modules/mymod.py validate-modules:missing-gplv3-license
Running Sanity Tests
With ansible-lint
# Lint entire collection
ansible-lint
# Lint specific paths
ansible-lint tests/sanity/
With ansible-test (Collection Development)
# Run all sanity tests
ansible-test sanity --docker
# Run specific sanity test
ansible-test sanity --test validate-modules
# Run for specific Python version
ansible-test sanity --python 3.12
Collection Structure Reference
my_collection/
├── galaxy.yml
├── plugins/
│ ├── modules/
│ │ └── my_module.py
│ └── module_utils/
│ └── helper.py
├── roles/
├── tests/
│ ├── sanity/
│ │ ├── ignore-2.16.txt ← Checked by sanity rule
│ │ └── ignore-2.17.txt ← Checked by sanity rule
│ ├── unit/
│ └── integration/
└── README.md
Red Hat Certification Relevance
The sanity rule is especially important for:
- Red Hat Certified Collections — must pass all sanity checks with no unpermitted ignores
- Ansible Galaxy publishing — collections with sanity failures may be flagged
- RHCE (EX294) exam — understanding collection quality standards
Certification Checklist
# Ensure your collection passes all checks
- ansible-lint passes with no errors
- ansible-test sanity passes cleanly
- Only permitted ignores in ignore-x.x.txt
- All modules have GPLv3 headers
- All modules have proper documentation
Suppressing the Rule
If you need to skip the sanity rule (not recommended for certification):
# .ansible-lint
skip_list:
- sanity
Or for specific sub-rules:
skip_list:
- sanity[cannot-ignore]
- sanity[bad-ignore]
Related Articles
- Ansible Lint Rule 302: deprecated-command-syntax
- Ansible Lint Rule 402: latest[hg]
- RHCE EX294 Exam Guide
- Ansible Galaxy: The Complete Guide
- Ansible Best Practices Guide
- Ansible-Core Guide
- Ansible Content Creator: ansible-creator
Conclusion
The sanity rule ensures your Ansible collection's ignore files only contain approved exemptions. The fix is usually simple: remove unpermitted ignores and fix the underlying code issues instead of trying to suppress them. For Red Hat Certification, passing sanity checks with clean ignore files is mandatory — treat this rule as a quality gate that keeps your collection maintainable and standards-compliant.