ansible.builtin.validate_argument_spec (v2.16.5) — module

Validate role argument specs.

| "added in version" 2.11 of ansible.builtin"

Authors: Ansible Core Team

This plugin has a corresponding action plugin.

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

This module validates role arguments with a defined argument specification.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- 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']}}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- 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!

Inputs

    
argument_spec:
    description:
    - A dictionary like AnsibleModule argument_spec. See R(argument spec definition,argument_spec)
    required: true

provided_arguments:
    description:
    - A dictionary of the arguments that will be validated according to argument_spec

Outputs

argument_errors:
  description: A list of arg validation errors.
  elements: str
  returned: failure
  sample:
  - error message 1
  - error message 2
  type: list
argument_spec_data:
  description: A dict of the data from the 'argument_spec' arg.
  returned: failure
  sample:
    some_arg:
      type: str
    some_other_arg:
      required: true
      type: int
  type: dict
validate_args_context:
  description: A dict of info about where validate_args_spec was used
  returned: always
  sample:
    argument_spec_name: main
    name: my_role
    path: /home/user/roles/my_role/
    type: role
  type: dict