Debian Codegraph @

test/integration/targets/task-args/tasks/main.yml

raw
1 # DTFIX-FUTURE: finish the full precedence description in DT docs and include it here
2
3 - name: validate templated raw params from the action statement and the args keyword are merged
4 echo: '{{ vp }}'
5 args: '{{ rp }}'
6 vars:
7 vp:
8 a: a from vp
9 b: b from vp
10 rp:
11 a: a from rp
12 c: c from rp
13 register: res
14
15 - assert:
16 that:
17 - res.action_args.a == 'a from vp'
18 - res.action_args.b == 'b from vp'
19 - res.action_args.c == 'c from rp'
20
21 - name: validate non-raw task arg precedence
22 echo: '{{ vp }} a={{ "templated a from k=v" }} chdir={{"from_kv"}} warn={{omit}} bogus={{omit}}'
23 args:
24 a: masked
25 b: '{{ "templated b from args" }}'
26 chdir: masked by kv
27 warn: masked by omit
28 vars:
29 vp:
30 a: masked
31 c: '{{ "templated c from vp" }}'
32 chdir: masked by kv/args
33 warn: masked by omit/args
34 register: res
35
36 - assert:
37 that:
38 - res.action_args.a == "templated a from k=v"
39 - res.action_args.b == "templated b from args"
40 - res.action_args.c == "templated c from vp"
41 - res.action_args.chdir == "from_kv"
42 - res.action_args is not contains "warn"
43
44
45 - name: validate raw task arg precedence
46 echo_raw: '{{ "vp_scalar" }} chdir={{"from_kv"}} warn={{omit}}' # devel omit is `obliterate`- does not support fallback
47 args:
48 a: '{{ "templated a from args" }}'
49 chdir: masked
50 warn: masked by omit
51 register: res
52
53 - assert:
54 that:
55 - res.action_args._raw_params == "vp_scalar"
56 - res.action_args.a == "templated a from args"
57 - res.action_args.chdir == "from_kv"
58 - res.action_args is not contains "warn"
59
60 ## Error cases
61
62 - name: non-raw vp args must be dict
63 echo: '{{ ["vp_list"] }}'
64 ignore_errors: true
65 register: res
66
67 - assert:
68 that: res is failed and res.msg is contains "must resolve to a 'dict'"
69
70 - name: non-raw vp args must be dict
71 echo: '{{ "foo" }} arg1=blah'
72 ignore_errors: true
73 register: res
74
75 - assert:
76 that: res is failed and res.msg is contains "must resolve to a 'dict'"
77
78 - name: presence of (templated, hence deferred) non-k=v tokens in _raw_params fails for non-raw actions
79 echo: a=aval {{ "non_kv_thing" }} b=bval
80 ignore_errors: true
81 register: res
82
83 - assert:
84 that: res is failed and res.msg is contains "must resolve to a 'dict'"
85
86 - name: leftover non k=v tokens for non-raw actions is an error
87 echo: a=aval non_kv_junk b=bval
88 ignore_errors: true
89 register: res
90
91 - assert:
92 that:
93 res.msg is contains "does not support raw params"
94
95 # normal precedence: action.kv, task args, variable_params
96 # special-case buggy precedence with action dict + `module`: action.args, action.module.kv, action.(discrete args), task args, variable_params
97 - name: assert (deprecated) buggy action.module arg precedence
98 action:
99 args: # precedence 0
100 a: from_action_args
101
102 module: echo {{ vp }} a=from_action_module_kv_masked b=from_action_module_kv # precedence 1
103
104 # precedence 2
105 a: from_discrete_args_masked
106 b: from_discrete_args_masked
107 c: from_discrete_args
108
109 args: # precedence 3
110 a: from_task_args_masked
111 b: from_task_args_masked
112 c: from_task_args_masked
113 d: from_task_args
114
115 vars: # precedence 4
116 vp:
117 a: from_vp_masked
118 b: from_vp_masked
119 c: from_vp_masked
120 d: from_vp_masked
121 e: from_vp
122 register: res
123
124 - assert:
125 that: |
126 res.action_args == {"a": "from_action_args", "b": "from_action_module_kv", "c": "from_discrete_args", "d": "from_task_args", "e": "from_vp"}
127
128 # DTFIX-FUTURE: ensure that we're testing the new behavior we want before nuking some/all of these "asserting broken/weird behavior" test cases
129 # Nonsensical cases, asserting existing weird-ish behavior
130
131 - name: (nonsensical, validating existing behavior) raw vp args template result gets stringified in _raw_params after shell k=v arg removal if k=v args remain
132 echo_raw: '{{ {"a":"stringified"} }} chdir=chdirvalue other=causes_vp_stringification'
133 register: res
134
135 - assert:
136 that:
137 #- res.action_args._raw_params is string
138 #- res.action_args._raw_params is not contains "chdir"
139 - res.action_args.chdir == "chdirvalue"
140
141 - name: (nonsensical, validating existing behavior) raw vp args template result preserves type in _raw_params after shell k=v arg removal if no k=v args remain
142 echo_raw: '{{ ["listval"] }} chdir=chdirvalue'
143 register: res
144
145 - assert:
146 that:
147 - res.action_args._raw_params[0] == "listval"
148 - res.action_args.chdir == "chdirvalue"
149
150 - name: (nonsensical, validating existing behavior) crazy busted inline kv parsing for non-raw actions
151 echo: a=aval {{ "k=v" }} {{ wtf=oopsquotes }} b=bval
152 vars:
153 kvstring: k=v
154 ignore_errors: true
155 register: res
156
157 - assert:
158 that:
159 - res.action_args.a == "aval"
160 - res.action_args.b == "bval"
161 - res.action_args['{'~'{ "k'] == 'v" }}'
162 - res.action_args['{'~'{ wtf'] == 'oopsquotes }}'
163
164 - name: (nonsensical, validating existing behavior) use legacy module arg with null value
165 action: echo
166 args:
167 module: ~
168 register: res
169
170 - assert:
171 that: res.action_args.module == none