ansible.builtin.validate_argument_spec – Validate role argument specs.

Note

This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name validate_argument_spec even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

New in version 2.11: of ansible.builtin

Synopsis

  • This module validates role arguments with a defined argument specification.

Note

This module has a corresponding action plugin.

Parameters

Parameter Choices/Defaults Comments
argument_spec
string / required
A dictionary like AnsibleModule argument_spec
provided_arguments
string
A dictionary of the arguments that will be validated according to argument_spec

Examples

- name: verify vars needed for this task file are present when included
  validate_argument_spec:
        argument_spec: '{{required_data}}'
  vars:
    required_data:
        # unlike spec file, just put the options in directly
        stuff:
            description: stuff
            type: str
            choices: ['who', 'knows', 'what']
            default: what
        but:
            description: i guess we need one
            type: str
            required: true


- name: verify vars needed for this task file are present when included, with spec from a spec file
  validate_argument_spec:
        argument_spec: "{{lookup('file', 'myargspec.yml')['specname']['options']}}"


- name: verify vars needed for next include and not from inside it, also with params i'll only define there
  block:
    - validate_argument_spec:
        argument_spec: "{{lookup('file', 'nakedoptions.yml'}}"
        provided_arguments:
            but: "that i can define on the include itself, like in it's `vars:` keyword"

    - name: the include itself
      vars:
        stuff: knows
        but: nobuts!

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
argument_errors
list / elements=string
failure
A list of arg validation errors.

Sample:
['error message 1', 'error message 2']
argument_spec_data
dictionary
failure
A dict of the data from the 'argument_spec' arg.

Sample:
{'some_arg': {'type': 'str'}, 'some_other_arg': {'required': True, 'type': 'int'}}
validate_args_context
dictionary
always
A dict of info about where validate_args_spec was used

Sample:
{'argument_spec_name': 'main', 'name': 'my_role', 'path': '/home/user/roles/my_role/', 'type': 'role'}


Authors

  • Ansible Core Team

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/validate_argument_spec_module.html