Debian Codegraph @

lib/ansible/modules/validate_argument_spec.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2021 Red Hat
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import annotations
7
8
9 DOCUMENTATION = r"""
10 ---
11 module: validate_argument_spec
12 short_description: Validate role argument specs.
13 description:
14 - This module validates role arguments with a defined argument specification.
15 version_added: "2.11"
16 options:
17 argument_spec:
18 description:
19 - A dictionary like AnsibleModule argument_spec.
20 - See the C(options) parameter for the R(specification format,role_argument_spec).
21 required: true
22 provided_arguments:
23 description:
24 - A dictionary of the arguments that will be validated according to argument_spec.
25 author:
26 - Ansible Core Team
27 extends_documentation_fragment:
28 - action_common_attributes
29 - action_common_attributes.conn
30 - action_common_attributes.flow
31 attributes:
32 action:
33 support: full
34 async:
35 support: none
36 become:
37 support: none
38 bypass_host_loop:
39 support: none
40 connection:
41 support: none
42 check_mode:
43 support: full
44 delegation:
45 support: none
46 diff_mode:
47 support: none
48 platform:
49 platforms: all
50 notes:
51 - It is unnecessary to call this module explicitly if the role contains an R(argument spec,role_argument_spec).
52 """
53
54 EXAMPLES = r"""
55 - name: verify vars needed for this task file are present when included
56 ansible.builtin.validate_argument_spec:
57 argument_spec: '{{ required_data }}'
58 vars:
59 required_data:
60 # unlike spec file, just put the options in directly
61 stuff:
62 description: stuff
63 type: str
64 choices: ['who', 'knows', 'what']
65 default: what
66 but:
67 description: i guess we need one
68 type: str
69 required: true
70
71
72 - name: verify vars needed for this task file are present when included, with spec from a spec file
73 ansible.builtin.validate_argument_spec:
74 argument_spec: "{{ (lookup('ansible.builtin.file', 'myargspec.yml') | from_yaml )['specname']['options'] }}"
75
76
77 - name: verify vars needed for next include and not from inside it, also with params i'll only define there
78 block:
79 - ansible.builtin.validate_argument_spec:
80 argument_spec: "{{ lookup('ansible.builtin.file', 'nakedoptions.yml') }}"
81 provided_arguments:
82 but: "that i can define on the include itself, like in it's `vars:` keyword"
83
84 - name: the include itself
85 vars:
86 stuff: knows
87 but: nobuts!
88 """
89
90 RETURN = r"""
91 argument_errors:
92 description: A list of arg validation errors.
93 returned: failure
94 type: list
95 elements: str
96 sample:
97 - "error message 1"
98 - "error message 2"
99
100 argument_spec_data:
101 description: A dict of the data from the 'argument_spec' arg.
102 returned: failure
103 type: dict
104 sample:
105 some_arg:
106 type: "str"
107 some_other_arg:
108 type: "int"
109 required: true
110
111 validate_args_context:
112 description: A dict of info about where validate_args_spec was used
113 type: dict
114 returned: always
115 sample:
116 name: my_role
117 type: role
118 path: /home/user/roles/my_role/
119 argument_spec_name: main
120 """