blob: aa9fc008021ec76ff9f26e29fe6c2b94a3a5b515 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# -*- coding: utf-8 -*-
# Copyright 2021 Red Hat
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import annotations
DOCUMENTATION = r"""
---
module: validate_argument_spec
short_description: Validate role argument specs.
description:
- This module validates role arguments with a defined argument specification.
version_added: "2.11"
options:
argument_spec:
description:
- A dictionary like AnsibleModule argument_spec.
- See the C(options) parameter for the R(specification format,role_argument_spec).
required: true
provided_arguments:
description:
- A dictionary of the arguments that will be validated according to argument_spec.
author:
- Ansible Core Team
extends_documentation_fragment:
- action_common_attributes
- action_common_attributes.conn
- action_common_attributes.flow
attributes:
action:
support: full
async:
support: none
become:
support: none
bypass_host_loop:
support: none
connection:
support: none
check_mode:
support: full
delegation:
support: none
diff_mode:
support: none
platform:
platforms: all
notes:
- It is unnecessary to call this module explicitly if the role contains an R(argument spec,role_argument_spec).
"""
EXAMPLES = r"""
- 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 = r"""
argument_errors:
description: A list of arg validation errors.
returned: failure
type: list
elements: str
sample:
- "error message 1"
- "error message 2"
argument_spec_data:
description: A dict of the data from the 'argument_spec' arg.
returned: failure
type: dict
sample:
some_arg:
type: "str"
some_other_arg:
type: "int"
required: true
validate_args_context:
description: A dict of info about where validate_args_spec was used
type: dict
returned: always
sample:
name: my_role
type: role
path: /home/user/roles/my_role/
argument_spec_name: main
"""
|