validate-modules¶
Python program to help test or validate Ansible modules.
validate-modules
is one of the ansible-test
Sanity Tests, see Sanity Tests 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 |
1xx |
Locations |
101 |
Interpreter line is not |
102 |
Interpreter line is not |
103 |
Did not find a call to |
104 |
Call to |
105 |
GPLv3 license header not found |
106 |
Import found before documentation variables. All imports must appear below
|
107 |
Imports should be directly below |
108 |
GPLv3 license header should be the short form for new modules |
109 |
Next to last line is not |
2xx |
Imports |
201 |
Did not find a |
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
Only the following |
210 |
|
211 |
|
3xx |
Documentation |
301 |
No |
302 |
|
303 |
|
304 |
Unknown |
305 |
Invalid |
306 |
Module level |
307 |
Module level |
308 |
|
309 |
|
310 |
No |
311 |
|
312 |
No |
313 |
|
314 |
No |
315 |
|
316 |
Invalid |
317 |
option is marked as required but specifies a default. Arguments with a default should not be marked as required |
318 |
Module marked as deprecated or removed in at least one of the filename, its metadata, or in DOCUMENTATION (setting DOCUMENTATION.deprecated for deprecation or removing all documentation for removed) but not in all three places. |
319 |
|
320 |
|
321 |
|
322 |
argument is listed in the argument_spec, but not documented in the module |
323 |
argument is listed in DOCUMENTATION.options, but not accepted by the module |
324 |
Value for “default” from the argument_spec does not match the documentation |
325 |
argument_spec defines type different than documentation does |
326 |
Value for “choices” from the argument_spec does not match the documentation |
327 |
Default value from the documentation is not compatible with type defined in the argument_spec |
328 |
Choices value from the documentation is not compatible with type defined in the argument_spec |
329 |
Default value from the argument_spec is not compatible with type defined in the argument_spec |
330 |
Choices value from the argument_spec is not compatible with type defined in the argument_spec |
331 |
argument in argument_spec must be a dictionary/hash when used |
332 |
|
333 |
|
334 |
|
335 |
argument_spec implies type=”str” but documentation defines it as different data type |
336 |
argument in argument_spec is not a valid python identifier |
4xx |
Syntax |
401 |
Python |
403 |
Type comparison using |
5xx |
Naming |
501 |
Official Ansible modules must have a |
502 |
Ansible module subdirectories must contain an |
503 |
Missing python documentation file |
Warnings¶
code |
sample message |
1xx |
Locations |
107 |
Imports should be directly below |
2xx |
Imports |
208 |
|
291 |
Try/Except |
292 |
Did not find |
3xx |
Documentation |
312 |
No |
391 |
Unknown pre-existing |
392 |
Pre-existing |