validate_argument_spec¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.11.
Synopsis¶
- This module validates role arguments with a defined argument specification.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| argument_spec required |
A dictionary like AnsibleModule argument_spec. See R(argument spec definition,argument_spec). | |
| provided_arguments | 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
ansible.builtin.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
ansible.builtin.validate_argument_spec:
argument_spec: "{{ (lookup('ansible.builtin.file', 'myargspec.yml') | from_yaml )['specname']['options'] }}"
- name: verify vars needed for next include and not from inside it, also with params i'll only define there
block:
- ansible.builtin.validate_argument_spec:
argument_spec: "{{ lookup('ansible.builtin.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¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| argument_errors | list | A list of arg validation errors. | failure |
| argument_spec_data | dict | A dict of the data from the 'argument_spec' arg. | failure |
| validate_args_context | dict | A dict of info about where validate_args_spec was used | always |
Authors¶
- Ansible Core Team