File: main.yml

package info (click to toggle)
ansible-core 2.19.0~beta6-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 32,628 kB
  • sloc: python: 180,313; cs: 4,929; sh: 4,601; xml: 34; makefile: 21
file content (171 lines) | stat: -rw-r--r-- 5,133 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# DTFIX-FUTURE: finish the full precedence decscription in DT docs and include it here

- name: validate templated raw params from the action statement and the args keyword are merged
  echo: '{{ vp }}'
  args: '{{ rp }}'
  vars:
    vp:
      a: a from vp
      b: b from vp
    rp:
      a: a from rp
      c: c from rp
  register: res

- assert:
    that:
      - res.action_args.a == 'a from vp'
      - res.action_args.b == 'b from vp'
      - res.action_args.c == 'c from rp'

- name: validate non-raw task arg precedence
  echo: '{{ vp }} a={{ "templated a from k=v" }} chdir={{"from_kv"}} warn={{omit}} bogus={{omit}}'
  args:
    a: masked
    b: '{{ "templated b from args" }}'
    chdir: masked by kv
    warn: masked by omit
  vars:
    vp:
      a: masked
      c: '{{ "templated c from vp" }}'
      chdir: masked by kv/args
      warn: masked by omit/args
  register: res

- assert:
    that:
      - res.action_args.a == "templated a from k=v"
      - res.action_args.b == "templated b from args"
      - res.action_args.c == "templated c from vp"
      - res.action_args.chdir == "from_kv"
      - res.action_args is not contains "warn"


- name: validate raw task arg precedence
  echo_raw: '{{ "vp_scalar" }} chdir={{"from_kv"}} warn={{omit}}' # devel omit is `obliterate`- does not support fallback
  args:
    a: '{{ "templated a from args" }}'
    chdir: masked
    warn: masked by omit
  register: res

- assert:
    that:
      - res.action_args._raw_params == "vp_scalar"
      - res.action_args.a == "templated a from args"
      - res.action_args.chdir == "from_kv"
      - res.action_args is not contains "warn"

## Error cases

- name: non-raw vp args must be dict
  echo: '{{ ["vp_list"] }}'
  ignore_errors: true
  register: res

- assert:
    that: res is failed and res.msg is contains "must resolve to a 'dict'"

- name: non-raw vp args must be dict
  echo: '{{ "foo" }} arg1=blah'
  ignore_errors: true
  register: res

- assert:
    that: res is failed and res.msg is contains "must resolve to a 'dict'"

- name: presence of (templated, hence deferred) non-k=v tokens in _raw_params fails for non-raw actions
  echo: a=aval {{ "non_kv_thing" }} b=bval
  ignore_errors: true
  register: res

- assert:
    that: res is failed and res.msg is contains "must resolve to a 'dict'"

- name: leftover non k=v tokens for non-raw actions is an error
  echo: a=aval non_kv_junk b=bval
  ignore_errors: true
  register: res

- assert:
    that:
      res.msg is contains "does not support raw params"

# normal precedence: action.kv, task args, variable_params
# special-case buggy precedence with action dict + `module`: action.args, action.module.kv, action.(discrete args), task args, variable_params
- name: assert (deprecated) buggy action.module arg precedence
  action:
    args: # precedence 0
      a: from_action_args

    module: echo {{ vp }} a=from_action_module_kv_masked b=from_action_module_kv  # precedence 1

    # precedence 2
    a: from_discrete_args_masked
    b: from_discrete_args_masked
    c: from_discrete_args

  args:  # precedence 3
    a: from_task_args_masked
    b: from_task_args_masked
    c: from_task_args_masked
    d: from_task_args

  vars:  # precedence 4
    vp:
      a: from_vp_masked
      b: from_vp_masked
      c: from_vp_masked
      d: from_vp_masked
      e: from_vp
  register: res

- assert:
    that: |
      res.action_args == {"a": "from_action_args", "b": "from_action_module_kv", "c": "from_discrete_args", "d": "from_task_args", "e": "from_vp"}

# DTFIX-FUTURE: ensure that we're testing the new behavior we want before nuking some/all of these "asserting broken/weird behavior" test cases
# Nonsensical cases, asserting existing weird-ish behavior

- 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
  echo_raw: '{{ {"a":"stringified"} }} chdir=chdirvalue other=causes_vp_stringification'
  register: res

- assert:
    that:
      #- res.action_args._raw_params is string
      #- res.action_args._raw_params is not contains "chdir"
      - res.action_args.chdir == "chdirvalue"

- 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
  echo_raw: '{{ ["listval"] }} chdir=chdirvalue'
  register: res

- assert:
    that:
      - res.action_args._raw_params[0] == "listval"
      - res.action_args.chdir == "chdirvalue"

- name: (nonsensical, validating existing behavior) crazy busted inline kv parsing for non-raw actions
  echo: a=aval {{ "k=v" }} {{ wtf=oopsquotes }} b=bval
  vars:
    kvstring: k=v
  ignore_errors: true
  register: res

- assert:
    that:
      - res.action_args.a == "aval"
      - res.action_args.b == "bval"
      - res.action_args['{'~'{ "k'] == 'v" }}'
      - res.action_args['{'~'{ wtf'] == 'oopsquotes }}'

- name: (nonsensical, validating existing behavior) use legacy module arg with null value
  action: echo
  args:
    module: ~
  register: res

- assert:
    that: res.action_args.module == none