2017-04-28 08:08:26 +00:00
***** ***** ***** *
2016-10-13 19:47:13 +00:00
validate-modules
2017-04-28 08:08:26 +00:00
***** ***** ***** *
.. contents :: Topics
2016-10-13 19:47:13 +00:00
Python program to help test or validate Ansible modules.
2017-04-28 08:08:26 +00:00
`` validate-modules `` is one of the `` ansible-test `` Sanity Tests, see :doc: `testing_sanity` for more information.
2016-10-13 19:47:13 +00:00
Originally developed by Matt Martz (@sivel)
2017-04-28 08:08:26 +00:00
2016-10-13 19:47:13 +00:00
Usage
2017-04-28 08:08:26 +00:00
=====
2016-10-13 19:47:13 +00:00
.. code :: shell
cd /path/to/ansible/source
source hacking/env-setup
2017-04-28 08:08:26 +00:00
ansible-test sanity --test validate-modules
2016-10-13 19:47:13 +00:00
Help
2017-04-28 08:08:26 +00:00
====
2016-10-13 19:47:13 +00:00
.. code :: shell
2017-02-20 21:28:23 +00:00
usage: validate-modules [-h] [-w] [--exclude EXCLUDE] [--arg-spec]
[--base-branch BASE_BRANCH] [--format {json,plain}]
[--output OUTPUT]
modules [modules ...]
2016-10-13 19:47:13 +00:00
positional arguments:
2017-02-20 21:28:23 +00:00
modules Path to module or module directory
2016-10-13 19:47:13 +00:00
optional arguments:
2017-02-20 21:28:23 +00:00
-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 "-"
2017-04-28 08:08:26 +00:00
Extending validate-modules
==========================
The `` validate-modules `` tool has a `schema.py <https://github.com/ansible/ansible/blob/devel/test/sanity/validate-modules/schema.py> `_ that is used to validate the YAML blocks, such as `` DOCUMENTATION `` and `` RETURNS `` .
2017-02-20 21:28:23 +00:00
Codes
2017-04-28 08:08:26 +00:00
=====
2016-10-13 19:47:13 +00:00
Errors
2017-04-28 08:08:26 +00:00
------
2016-10-13 19:47:13 +00:00
2017-07-27 10:37:32 +00:00
========= ===================
code sample message
--------- -------------------
**1xx** **Locations**
101 Interpreter line is not `` #!/usr/bin/python ``
102 Interpreter line is not `` #!powershell ``
2018-01-30 12:23:52 +00:00
103 Did not find a call to `` main() `` (or `` removed_module() `` in the case of deprecated & docs only modules)
104 Call to `` main() `` not the last line (or `` removed_module() `` in the case of deprecated & docs only modules)
2017-07-27 10:37:32 +00:00
105 GPLv3 license header not found
106 Import found before documentation variables. All imports must appear below
`` DOCUMENTATION `` /`` EXAMPLES `` /`` RETURN `` /`` ANSIBLE_METADATA ``
107 Imports should be directly below `` DOCUMENTATION `` /`` EXAMPLES `` /`` RETURN `` /`` ANSIBLE_METADATA ``
2017-12-16 17:23:54 +00:00
108 GPLv3 license header should be the :ref: `short form <copyright>` for new modules
2018-01-15 15:49:35 +00:00
109 Next to last line is not `` if __name__ == "__main__": ``
2017-07-27 10:37:32 +00:00
..
--------- -------------------
**2xx** **Imports**
201 Did not find a `` module_utils `` import
203 `` requests `` import found, should use `` ansible.module_utils.urls `` instead
204 `` boto `` import found, new modules should use `` boto3 ``
205 `` sys.exit() `` call found. Should be `` exit_json `` /`` fail_json ``
206 `` WANT_JSON `` not found in module
207 `` REPLACER_WINDOWS `` not found in module
208 `` module_utils `` imports should import specific components, not `` * ``
209 Only the following `` from __future__ `` imports are allowed:
`` absolute_import `` , `` division `` , and `` print_function `` .
2018-06-21 15:58:39 +00:00
210 `` subprocess.Popen `` used instead of `` module.run_command ``
211 `` os.call `` used instead of `` module.run_command ``
2017-07-27 10:37:32 +00:00
..
--------- -------------------
**3xx** **Documentation**
301 No `` DOCUMENTATION `` provided
302 `` DOCUMENTATION `` is not valid YAML
303 `` DOCUMENTATION `` fragment missing
304 Unknown `` DOCUMENTATION `` error
305 Invalid `` DOCUMENTATION `` schema
306 Module level `` version_added `` is not a valid version number
307 Module level `` version_added `` is incorrect
308 `` version_added `` for new option is not a valid version number
309 `` version_added `` for new option is incorrect
310 No `` EXAMPLES `` provided
311 `` EXAMPLES `` is not valid YAML
312 No `` RETURN `` documentation provided
313 `` RETURN `` is not valid YAML
314 No `` ANSIBLE_METADATA `` provided
2018-01-17 20:15:22 +00:00
315 `` ANSIBLE_METADATA `` was not provided as a dict, YAML not supported
2017-07-27 10:37:32 +00:00
316 Invalid `` ANSIBLE_METADATA `` schema
317 option is marked as required but specifies a default.
Arguments with a default should not be marked as required
318 Module deprecated, but DOCUMENTATION.deprecated is missing
319 `` RETURN `` fragments missing or invalid
2017-12-06 00:18:01 +00:00
320 `` DOCUMENTATION.options `` must be a dictionary/hash when used
2018-01-11 23:41:53 +00:00
321 `` Exception `` attempting to import module for `` argument_spec `` introspection
2018-01-17 16:11:30 +00:00
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
2018-02-15 20:34:40 +00:00
324 Value for "default" from the argument_spec does not match the documentation
325 argument_spec defines type="bool" but documentation does not
326 Value for "choices" from the argument_spec does not match the documentation
2018-03-26 17:15:32 +00:00
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
2018-06-20 16:05:49 +00:00
331 argument in argument_spec must be a dictionary/hash when used
2018-07-31 20:04:22 +00:00
332 `` AnsibleModule `` schema validation error
2017-07-27 10:37:32 +00:00
..
--------- -------------------
**4xx** **Syntax**
401 Python `` SyntaxError `` while parsing module
403 Type comparison using `` type() `` found. Use `` isinstance() `` instead
..
--------- -------------------
**5xx** **Naming**
501 Official Ansible modules must have a `` .py `` extension for python
modules or a `` .ps1 `` for powershell modules
502 Ansible module subdirectories must contain an `` __init__.py ``
503 Missing python documentation file
========= ===================
2016-10-13 19:47:13 +00:00
Warnings
2017-04-28 08:08:26 +00:00
--------
2016-10-13 19:47:13 +00:00
2017-07-27 10:37:32 +00:00
========= ===================
code sample message
--------- -------------------
**1xx** **Locations**
107 Imports should be directly below `` DOCUMENTATION `` /`` EXAMPLES `` /`` RETURN `` /`` ANSIBLE_METADATA `` for legacy modules
..
--------- -------------------
**2xx** **Imports**
208 `` module_utils `` imports should import specific components for legacy module, not `` * ``
291 Try/Except `` HAS_ `` expression missing
292 Did not find `` ansible.module_utils.basic `` import
..
--------- -------------------
**3xx** **Documentation**
312 No `` RETURN `` documentation provided for legacy module
391 Unknown pre-existing `` DOCUMENTATION `` error
392 Pre-existing `` DOCUMENTATION `` fragment missing
========= ===================