Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tests.yml « tasks « group « targets « integration « test - github.com/ansible/ansible.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f81f570b6f954b96812466828c9a2d6ac16aed64 (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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
---
- name: ensure test groups are deleted before the test
  group:
    name: '{{ item }}'
    state: absent
  loop:
    - ansibullgroup
    - ansibullgroup2
    - ansibullgroup3

- block:
    ##
    ## group add
    ##

    - name: create group (check mode)
      group:
        name: ansibullgroup
        state: present
      register: create_group_check
      check_mode: true

    - name: get result of create group (check mode)
      script: 'grouplist.sh "{{ ansible_distribution }}"'
      register: create_group_actual_check

    - name: assert create group (check mode)
      assert:
        that:
          - create_group_check is changed
          - '"ansibullgroup" not in create_group_actual_check.stdout_lines'

    - name: create group
      group:
        name: ansibullgroup
        state: present
      register: create_group

    - name: get result of create group
      script: 'grouplist.sh "{{ ansible_distribution }}"'
      register: create_group_actual

    - name: assert create group
      assert:
        that:
          - create_group is changed
          - create_group.gid is defined
          - '"ansibullgroup" in create_group_actual.stdout_lines'

    - name: create group (idempotent)
      group:
        name: ansibullgroup
        state: present
      register: create_group_again

    - name: assert create group (idempotent)
      assert:
        that:
          - not create_group_again is changed

    ##
    ## group check
    ##

    - name: run existing group check tests
      group:
        name: "{{ create_group_actual.stdout_lines|random }}"
        state: present
      with_sequence: start=1 end=5
      register: group_test1

    - name: validate results for testcase 1
      assert:
        that:
          - group_test1.results is defined
          - group_test1.results|length == 5

    - name: validate change results for testcase 1
      assert:
        that:
          - not group_test1 is changed

    ##
    ## group add with gid
    ##

    - name: get the next available gid
      script: get_free_gid.py
      args:
        executable: '{{ ansible_python_interpreter }}'
      register: gid

    - name: create a group with a gid (check mode)
      group:
        name: ansibullgroup2
        gid: '{{ gid.stdout_lines[0] }}'
        state: present
      register: create_group_gid_check
      check_mode: true

    - name: get result of create a group with a gid (check mode)
      script: 'grouplist.sh "{{ ansible_distribution }}"'
      register: create_group_gid_actual_check

    - name: assert create group with a gid (check mode)
      assert:
        that:
          - create_group_gid_check is changed
          - '"ansibullgroup2" not in create_group_gid_actual_check.stdout_lines'

    - name: create a group with a gid
      group:
        name: ansibullgroup2
        gid: '{{ gid.stdout_lines[0] }}'
        state: present
      register: create_group_gid

    - name: get gid of created group
      script: "get_gid_for_group.py ansibullgroup2"
      args:
        executable: '{{ ansible_python_interpreter }}'
      register: create_group_gid_actual

    - name: assert create group with a gid
      assert:
        that:
          - create_group_gid is changed
          - create_group_gid.gid | int == gid.stdout_lines[0] | int
          - create_group_gid_actual.stdout | trim | int == gid.stdout_lines[0] | int

    - name: create a group with a gid (idempotent)
      group:
        name: ansibullgroup2
        gid: '{{ gid.stdout_lines[0] }}'
        state: present
      register: create_group_gid_again

    - name: assert create group with a gid (idempotent)
      assert:
        that:
          - not create_group_gid_again is changed
          - create_group_gid_again.gid | int == gid.stdout_lines[0] | int

    - block:
        - name: create a group with a non-unique gid
          group:
            name: ansibullgroup3
            gid: '{{ gid.stdout_lines[0] }}'
            non_unique: true
            state: present
          register: create_group_gid_non_unique

        - name: validate gid required with non_unique
          group:
            name: foo
            non_unique: true
          register: missing_gid
          ignore_errors: true

        - name: assert create group with a non unique gid
          assert:
            that:
              - create_group_gid_non_unique is changed
              - create_group_gid_non_unique.gid | int == gid.stdout_lines[0] | int
              - missing_gid is failed
      when: ansible_facts.distribution not in ['MacOSX', 'Alpine']

    ##
    ## group remove
    ##

    - name: delete group (check mode)
      group:
        name: ansibullgroup
        state: absent
      register: delete_group_check
      check_mode: true

    - name: get result of delete group (check mode)
      script: 'grouplist.sh "{{ ansible_distribution }}"'
      register: delete_group_actual_check

    - name: assert delete group (check mode)
      assert:
        that:
          - delete_group_check is changed
          - '"ansibullgroup" in delete_group_actual_check.stdout_lines'

    - name: delete group
      group:
        name: ansibullgroup
        state: absent
      register: delete_group

    - name: get result of delete group
      script: 'grouplist.sh "{{ ansible_distribution }}"'
      register: delete_group_actual

    - name: assert delete group
      assert:
        that:
          - delete_group is changed
          - '"ansibullgroup" not in delete_group_actual.stdout_lines'

    - name: delete group (idempotent)
      group:
        name: ansibullgroup
        state: absent
      register: delete_group_again

    - name: assert delete group (idempotent)
      assert:
        that:
          - not delete_group_again is changed

    - name: Ensure lgroupadd is present
      action: "{{ ansible_facts.pkg_mgr }}"
      args:
        name: libuser
        state: present
      when: ansible_facts.system in ['Linux'] and ansible_distribution != 'Alpine' and ansible_os_family != 'Suse'
      tags:
        - user_test_local_mode

    - name: Ensure lgroupadd is present - Alpine
      command: apk add -U libuser
      when: ansible_distribution == 'Alpine'
      tags:
        - user_test_local_mode

    # https://github.com/ansible/ansible/issues/56481
    - block:
        - name: Test duplicate GID with local=yes
          group:
            name: "{{ item }}"
            gid: 1337
            local: true
          loop:
            - group1_local_test
            - group2_local_test
          ignore_errors: true
          register: local_duplicate_gid_result

        - assert:
            that:
              - local_duplicate_gid_result['results'][0] is success
              - local_duplicate_gid_result['results'][1]['msg'] == "GID '1337' already exists with group 'group1_local_test'"
      always:
        - name: Cleanup
          group:
            name: group1_local_test
            state: absent
      # only applicable to Linux, limit further to CentOS where 'luseradd' is installed
      when: ansible_distribution == 'CentOS'

    # https://github.com/ansible/ansible/pull/59769
    - block:
        - name: create a local group with a gid
          group:
            name: group1_local_test
            gid: 1337
            local: true
            state: present
          register: create_local_group_gid

        - name: get gid of created local group
          script: "get_gid_for_group.py group1_local_test"
          args:
            executable: '{{ ansible_python_interpreter }}'
          register: create_local_group_gid_actual

        - name: assert create local group with a gid
          assert:
            that:
              - create_local_group_gid is changed
              - create_local_group_gid.gid | int == 1337 | int
              - create_local_group_gid_actual.stdout | trim | int == 1337 | int

        - name: create a local group with a gid (idempotent)
          group:
            name: group1_local_test
            gid: 1337
            state: present
          register: create_local_group_gid_again

        - name: assert create local group with a gid (idempotent)
          assert:
            that:
              - not create_local_group_gid_again is changed
              - create_local_group_gid_again.gid | int == 1337 | int
      always:
        - name: Cleanup create local group with a gid
          group:
            name: group1_local_test
            state: absent
      # only applicable to Linux, limit further to CentOS where 'luseradd' is installed
      when: ansible_distribution == 'CentOS'

    # https://github.com/ansible/ansible/pull/59772
    - block:
        - name: create group with a gid
          group:
            name: group1_test
            gid: 1337
            local: false
            state: present
          register: create_group_gid

        - name: get gid of created group
          script: "get_gid_for_group.py group1_test"
          args:
            executable: '{{ ansible_python_interpreter }}'
          register: create_group_gid_actual

        - name: assert create group with a gid
          assert:
            that:
              - create_group_gid is changed
              - create_group_gid.gid | int == 1337 | int
              - create_group_gid_actual.stdout | trim | int == 1337 | int

        - name: create local group with the same gid
          group:
            name: group1_test
            gid: 1337
            local: true
            state: present
          register: create_local_group_gid

        - name: assert create local group with a gid
          assert:
            that:
              - create_local_group_gid.gid | int == 1337 | int
      always:
        - name: Cleanup create group with a gid
          group:
            name: group1_test
            local: false
            state: absent
        - name: Cleanup create local group with the same gid
          group:
            name: group1_test
            local: true
            state: absent
      # only applicable to Linux, limit further to CentOS where 'lgroupadd' is installed
      when: ansible_distribution == 'CentOS'

    # create system group

    - name: remove group
      group:
        name: ansibullgroup
        state: absent

    - name: create system group
      group:
        name: ansibullgroup
        state: present
        system: true

  always:
    - name: remove test groups after test
      group:
        name: '{{ item }}'
        state: absent
      loop:
        - ansibullgroup
        - ansibullgroup2
        - ansibullgroup3