5.8 KiB
validate-modules
Topics
Python program to help test or validate Ansible modules.
validate-modules
is one of the ansible-test
Sanity Tests, see testing_sanity
for more information.
Originally developed by Matt Martz (@sivel)
Usage
cd /path/to/ansible/source
source hacking/env-setup
ansible-test sanity --test validate-modules
Help
usage: validate-modules [-h] [-w] [--exclude EXCLUDE] [--arg-spec]
[--base-branch BASE_BRANCH] [--format {json,plain}]
[--output OUTPUT]
modules [modules ...]
positional arguments:
modules Path to module or module directory
optional arguments:
-h, --help show this help message and exit
-w, --warnings Show warnings
--exclude EXCLUDE RegEx exclusion pattern
--arg-spec Analyze module argument spec
--base-branch BASE_BRANCH
Used in determining if new options were added
--format {json,plain}
Output format. Default: "plain"
--output OUTPUT Output location, use "-" for stdout. Default "-"
Extending validate-modules
The validate-modules
tool has a schema.py
that is used to validate the YAML blocks, such as
DOCUMENTATION
and RETURNS
.
Codes
Errors
code | sample message |
---|---|
|
Locations |
|
Interpreter line is not #!/usr/bin/python |
|
Interpreter line is not #!powershell |
|
Did not find a call to main() |
|
Call to main() not the last line |
|
GPLv3 license header not found |
|
Import found before documentation variables. All imports must
appear below
|
|
Imports should be directly below
DOCUMENTATION /EXAMPLES /RETURN /ANSIBLE_METADATA |
|
GPLv3 license header should be the short form <copyright> for new modules |
|
Next to last line is not
|
--------- | ------------------- |
|
Imports |
|
Did not find a module_utils import |
|
requests import found, should use
ansible.module_utils.urls instead |
|
boto import found, new modules should use
boto3 |
|
sys.exit() call found. Should be
exit_json /fail_json |
|
WANT_JSON not found in module |
|
REPLACER_WINDOWS not found in module |
|
module_utils imports should import specific components,
not * |
|
Only the following |
--------- | ------------------- |
|
Documentation |
|
No DOCUMENTATION provided |
|
DOCUMENTATION is not valid YAML |
|
DOCUMENTATION fragment missing |
|
Unknown DOCUMENTATION error |
|
Invalid DOCUMENTATION schema |
|
Module level version_added is not a valid version
number |
|
Module level version_added is incorrect |
|
version_added for new option is not a valid version
number |
|
version_added for new option is incorrect |
|
No EXAMPLES provided |
|
EXAMPLES is not valid YAML |
|
No RETURN documentation provided |
|
RETURN is not valid YAML |
|
No ANSIBLE_METADATA provided |
|
ANSIBLE_METADATA was not provided as a dict, YAML not
supported |
|
Invalid ANSIBLE_METADATA schema |
|
option is marked as required but specifies a default. Arguments with a default should not be marked as required |
|
Module deprecated, but DOCUMENTATION.deprecated is missing |
|
RETURN fragments missing or invalid |
|
DOCUMENTATION.options must be a dictionary/hash when
used |
|
Exception attempting to import module for
argument_spec introspection |
|
argument is listed in the argument_spec, but not documented in the module |
|
argument is listed in DOCUMENTATION.options, but not accepted by the module |
--------- | ------------------- |
|
Syntax |
|
Python SyntaxError while parsing module |
|
Indentation contains tabs |
|
Type comparison using |
--------- | ------------------- |
|
Naming |
|
Official Ansible modules must have a |
|
Ansible module subdirectories must contain an
__init__.py |
|
Missing python documentation file |
Warnings
code | sample message |
---|---|
|
Locations |
|
Imports should be directly below
|
--------- | ------------------- |
|
Imports |
|
module_utils imports should import specific components
for legacy module, not * |
|
Try/Except HAS_ expression missing |
|
Did not find |
--------- | ------------------- |
|
Documentation |
|
No RETURN documentation provided for legacy module |
|
Unknown pre-existing DOCUMENTATION error |
|
Pre-existing DOCUMENTATION fragment missing |