ansible.builtin.validate_argument_spec 模块 – 验证角色参数规范。

注意

此模块是 ansible-core 的一部分,包含在所有 Ansible 安装中。 在大多数情况下,即使不指定 collections 关键字,也可以使用简短的模块名称 validate_argument_spec。 但是,我们建议您使用 完全限定的集合名称 (FQCN) ansible.builtin.validate_argument_spec 来方便链接到模块文档,并避免与可能具有相同模块名称的其他集合发生冲突。

ansible-core 2.11 中新增

概要

  • 此模块使用定义的参数规范验证角色参数。

注意

此模块有一个相应的 操作插件

参数

参数

注释

argument_spec

字符串 / 必需

类似于 AnsibleModule argument_spec 的字典。 请参阅 参数规范定义

provided_arguments

字符串

将根据 argument_spec 验证的参数字典。

属性

属性

支持

描述

action

支持:完全支持

表示此模块具有对应的操作插件,因此某些选项部分可以在控制器上执行

async

支持:不支持

支持与 async 关键字一起使用

become

支持:不支持

可与 become 关键字一起使用

bypass_host_loop

支持:不支持

强制执行不按主机执行的“全局”任务,这将绕过按主机进行的模板化、串行、节流和其他循环考虑因素

条件语句将按使用 run_once 的方式工作,使用的变量将来自第一个可用主机

此操作在步进策略之外无法正常工作

check_mode

支持:完全支持

可以在 check_mode 中运行并返回更改状态预测,而不会修改目标,如果不受支持,则会跳过该操作。

connection

支持:不支持

使用目标的配置连接信息在目标上执行代码

delegation

支持:不支持

可与 delegate_to 和相关关键字一起使用

diff_mode

支持:不支持

将在 diff 模式下返回关于发生了什么变化(或者可能需要在 check_mode 中更改)的详细信息

platform

平台: 所有

可以对其进行操作的目标操作系统/系列

示例

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

返回值

常见返回值已在 此处 记录,以下列出了此模块独有的字段

描述

argument_errors

列表 / 元素=字符串

参数验证错误列表。

返回:失败

示例: ["error message 1", "error message 2"]

argument_spec_data

字典

来自 'argument_spec' 参数的数据字典。

返回:失败

示例: {"some_arg": {"type": "str"}, "some_other_arg": {"required": true, "type": "int"}}

validate_args_context

字典

关于使用 validate_args_spec 的位置的信息字典

返回:始终

示例: {"argument_spec_name": "main", "name": "my_role", "path": "/home/user/roles/my_role/", "type": "role"}

作者

  • Ansible 核心团队