summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/module_defaults/test_defaults.yml
blob: 6206d3a945a6982ec9389b92bd6681cd6fd7479c (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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
- hosts: localhost
  gather_facts: no
  collections:
  - testns.testcoll
  - testns.othercoll
  module_defaults:
    testns.testcoll.echoaction:
      explicit_module_default: from playbook
    testns.testcoll.echo1:
      explicit_module_default: from playbook
    group/testgroup:
      group_module_default: from playbook
  tasks:
  - testns.testcoll.echoaction:
      task_arg: from task
    register: echoaction_fq
  - echoaction:
      task_arg: from task
    register: echoaction_unq
  - testns.testcoll.echo1:
      task_arg: from task
    register: echo1_fq
  - echo1:
      task_arg: from task
    register: echo1_unq
  - testns.testcoll.echo2:
      task_arg: from task
    register: echo2_fq
  - echo2:
      task_arg: from task
    register: echo2_unq
  - testns.othercoll.other_echoaction:
      task_arg: from task
    register: other_echoaction_fq
  - other_echoaction:
      task_arg: from task
    register: other_echoaction_unq
  - testns.othercoll.other_echo1:
      task_arg: from task
    register: other_echo1_fq
  - other_echo1:
      task_arg: from task
    register: other_echo1_unq

  - debug: var=echo1_fq

  - legacy_ping:
    register: legacy_ping_1
    module_defaults:
      legacy_ping:
        data: from task

  - legacy_ping:
    register: legacy_ping_2
    module_defaults:
      ansible.legacy.legacy_ping:
        data: from task

  - ansible.legacy.legacy_ping:
    register: legacy_ping_3
    module_defaults:
      legacy_ping:
        data: from task

  - ansible.legacy.legacy_ping:
    register: legacy_ping_4
    module_defaults:
      ansible.legacy.legacy_ping:
        data: from task

  - name: builtin uses legacy defaults
    ansible.builtin.debug:
    module_defaults:
      debug:
        msg: legacy default
    register: builtin_legacy_defaults_1

  - name: builtin uses legacy defaults
    ansible.builtin.debug:
    module_defaults:
      ansible.legacy.debug:
        msg: legacy default
    register: builtin_legacy_defaults_2

  - name: legacy does not use builtin defaults
    ansible.legacy.debug:
    register: legacy_builtin_defaults
    module_defaults:
      ansible.builtin.debug:
        msg: legacy default

  - assert:
      that:
        - "echoaction_fq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
        - "echoaction_unq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
        - "echo1_fq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
        - "echo1_unq.args_in == {'task_arg': 'from task', 'explicit_module_default': 'from playbook', 'group_module_default': 'from playbook' }"
        - "echo2_fq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
        - "echo2_unq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
        - "other_echoaction_fq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
        - "other_echoaction_unq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
        - "other_echo1_fq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
        - "other_echo1_unq.args_in == {'task_arg': 'from task', 'group_module_default': 'from playbook' }"
        - "legacy_ping_1.ping == 'from task'"
        - "legacy_ping_2.ping == 'from task'"
        - "legacy_ping_3.ping == 'from task'"
        - "legacy_ping_4.ping == 'from task'"
        - "legacy_builtin_defaults.msg == 'Hello world!'"
        - "builtin_legacy_defaults_1.msg == 'legacy default'"
        - "builtin_legacy_defaults_2.msg == 'legacy default'"

  - include_tasks: tasks/main.yml

- name: test preferring module name defaults for platform-specific actions
  hosts: localhost
  gather_facts: no
  tasks:
  - name: ensure eosfacts does not use action plugin default
    testns.testcoll.eosfacts:
    module_defaults:
      testns.testcoll.eos:
        fail: true

  - name: eosfacts does use module name defaults
    testns.testcoll.eosfacts:
    module_defaults:
      testns.testcoll.eosfacts:
        eosfacts: true
    register: result

  - assert:
      that:
        - result.eosfacts
        - result.action_plugin == 'eos'

  - name: ensure vyosfacts does not use action plugin default
    testns.testcoll.vyosfacts:
    module_defaults:
      testns.testcoll.vyos:
        fail: true

  - name: vyosfacts does use vyosfacts defaults
    testns.testcoll.vyosfacts:
    module_defaults:
      testns.testcoll.vyosfacts:
        vyosfacts: true
    register: result

  - assert:
      that:
        - result.vyosfacts
        - result.action_plugin == 'vyos'

  - name: iosfacts/ios_facts does not use action plugin default (module action_plugin field has precedence over module-as-action-redirect)
    collections:
      - testns.testcoll
    module_defaults:
      testns.testcoll.ios:
        fail: true
    block:
      - ios_facts:
        register: result
      - assert:
          that:
            - result.action_plugin == 'ios'

      - iosfacts:
        register: result
      - assert:
          that:
            - result.action_plugin == 'ios'

  - name: ensure iosfacts/ios_facts uses ios_facts defaults
    collections:
      - testns.testcoll
    module_defaults:
      testns.testcoll.ios_facts:
        ios_facts: true
    block:
      - ios_facts:
        register: result
      - assert:
          that:
            - result.ios_facts
            - result.action_plugin == 'ios'

      - iosfacts:
        register: result
      - assert:
          that:
            - result.ios_facts
            - result.action_plugin == 'ios'

  - name: ensure iosfacts/ios_facts uses iosfacts defaults
    collections:
      - testns.testcoll
    module_defaults:
      testns.testcoll.iosfacts:
        ios_facts: true
    block:
      - ios_facts:
        register: result
      - assert:
          that:
            - result.ios_facts
            - result.action_plugin == 'ios'

      - iosfacts:
        register: result
      - assert:
          that:
            - result.ios_facts
            - result.action_plugin == 'ios'

  - name: ensure redirected action gets redirected action defaults
    testns.testcoll.module_uses_action_defaults:
    module_defaults:
      testns.testcoll.module_uses_action_defaults:
        action_option: true
    register: result

  - assert:
      that:
        - result.action_option
        - result.action_plugin == 'eos'

  - name: ensure redirected action gets resolved action defaults
    testns.testcoll.module_uses_action_defaults:
    module_defaults:
      testns.testcoll.eos:
        action_option: true
    register: result

  - assert:
      that:
        - result.action_option
        - result.action_plugin == 'eos'

  - name: ensure redirected action does not use module-specific defaults
    testns.testcoll.module_uses_action_defaults:
    module_defaults:
      testns.testcoll.module:
        fail: true
    register: result

  - assert:
      that:
        - not result.action_option
        - result.action_plugin == 'eos'