ansible.builtin.validate_argument_spec 模块 – 验证角色参数规范。
注意
此模块是 ansible-core
的一部分,包含在所有 Ansible 安装中。 在大多数情况下,即使不指定 collections 关键字,也可以使用简短的模块名称 validate_argument_spec
。 但是,我们建议您使用 完全限定的集合名称 (FQCN) ansible.builtin.validate_argument_spec
来方便链接到模块文档,并避免与可能具有相同模块名称的其他集合发生冲突。
ansible-core 2.11 中新增
概要
此模块使用定义的参数规范验证角色参数。
注意
此模块有一个相应的 操作插件。
参数
参数 |
注释 |
---|---|
类似于 AnsibleModule argument_spec 的字典。 请参阅 参数规范定义。 |
|
将根据 argument_spec 验证的参数字典。 |
属性
属性 |
支持 |
描述 |
---|---|---|
支持:完全支持 |
表示此模块具有对应的操作插件,因此某些选项部分可以在控制器上执行 |
|
支持:不支持 |
支持与 |
|
支持:不支持 |
可与 become 关键字一起使用 |
|
支持:不支持 |
强制执行不按主机执行的“全局”任务,这将绕过按主机进行的模板化、串行、节流和其他循环考虑因素 条件语句将按使用 此操作在步进策略之外无法正常工作 |
|
支持:完全支持 |
可以在 check_mode 中运行并返回更改状态预测,而不会修改目标,如果不受支持,则会跳过该操作。 |
|
支持:不支持 |
使用目标的配置连接信息在目标上执行代码 |
|
支持:不支持 |
可与 delegate_to 和相关关键字一起使用 |
|
支持:不支持 |
将在 diff 模式下返回关于发生了什么变化(或者可能需要在 check_mode 中更改)的详细信息 |
|
平台: 所有 |
可以对其进行操作的目标操作系统/系列 |
示例
- 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_spec' 参数的数据字典。 返回:失败 示例: |
|
关于使用 validate_args_spec 的位置的信息字典 返回:始终 示例: |