summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-galaxy-collection/tasks/install.yml
blob: 9c14e8a820edffdaecb5ff6364052882fe81daca (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
---
- name: create test collection install directory - {{ test_name }}
  file:
    path: '{{ galaxy_dir }}/ansible_collections'
    state: directory

- name: install simple collection with implicit path - {{ test_name }}
  command: ansible-galaxy collection install namespace1.name1 -s '{{ test_server }}' {{ galaxy_verbosity }}
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
  register: install_normal

- name: get installed files of install simple collection with implicit path - {{ test_name }}
  find:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
    file_type: file
  register: install_normal_files

- name: get the manifest of install simple collection with implicit path - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
  register: install_normal_manifest

- name: assert install simple collection with implicit path - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace1.name1:1.0.9'' to" in install_normal.stdout'
    - install_normal_files.files | length == 3
    - install_normal_files.files[0].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
    - install_normal_files.files[1].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
    - install_normal_files.files[2].path | basename in ['MANIFEST.json', 'FILES.json', 'README.md']
    - (install_normal_manifest.content | b64decode | from_json).collection_info.version == '1.0.9'

- name: install existing without --force - {{ test_name }}
  command: ansible-galaxy collection install namespace1.name1 -s '{{ test_server }}' {{ galaxy_verbosity }}
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
  register: install_existing_no_force

- name: assert install existing without --force - {{ test_name }}
  assert:
    that:
    - '"Skipping ''namespace1.name1'' as it is already installed" in install_existing_no_force.stdout'

- name: install existing with --force - {{ test_name }}
  command: ansible-galaxy collection install namespace1.name1 -s '{{ test_server }}' --force {{ galaxy_verbosity }}
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
  register: install_existing_force

- name: assert install existing with --force - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace1.name1:1.0.9'' to" in install_existing_force.stdout'

- name: remove test installed collection - {{ test_name }}
  file:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1'
    state: absent

- name: install pre-release as explicit version to custom dir - {{ test_name }}
  command: ansible-galaxy collection install 'namespace1.name1:1.1.0-beta.1' -s '{{ test_server }}' -p '{{ galaxy_dir }}/ansible_collections' {{ galaxy_verbosity }}
  register: install_prerelease

- name: get result of install pre-release as explicit version to custom dir - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
  register: install_prerelease_actual

- name: assert install pre-release as explicit version to custom dir - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace1.name1:1.1.0-beta.1'' to" in install_prerelease.stdout'
    - (install_prerelease_actual.content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'

- name: Remove beta
  file:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1'
    state: absent

- name: install pre-release version with --pre to custom dir - {{ test_name }}
  command: ansible-galaxy collection install --pre 'namespace1.name1' -s '{{ test_server }}' -p '{{ galaxy_dir }}/ansible_collections' {{ galaxy_verbosity }}
  register: install_prerelease

- name: get result of install pre-release version with --pre to custom dir - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
  register: install_prerelease_actual

- name: assert install pre-release version with --pre to custom dir - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace1.name1:1.1.0-beta.1'' to" in install_prerelease.stdout'
    - (install_prerelease_actual.content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'

- name: install multiple collections with dependencies - {{ test_name }}
  command: ansible-galaxy collection install parent_dep.parent_collection namespace2.name -s {{ test_name }} {{ galaxy_verbosity }}
  args:
    chdir: '{{ galaxy_dir }}/ansible_collections'
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
    ANSIBLE_CONFIG: '{{ galaxy_dir }}/ansible.cfg'
  register: install_multiple_with_dep

- name: get result of install multiple collections with dependencies - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/{{ collection.namespace }}/{{ collection.name }}/MANIFEST.json'
  register: install_multiple_with_dep_actual
  loop_control:
    loop_var: collection
  loop:
  - namespace: namespace2
    name: name
  - namespace: parent_dep
    name: parent_collection
  - namespace: child_dep
    name: child_collection
  - namespace: child_dep
    name: child_dep2

- name: assert install multiple collections with dependencies - {{ test_name }}
  assert:
    that:
    - (install_multiple_with_dep_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
    - (install_multiple_with_dep_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
    - (install_multiple_with_dep_actual.results[2].content | b64decode | from_json).collection_info.version == '0.9.9'
    - (install_multiple_with_dep_actual.results[3].content | b64decode | from_json).collection_info.version == '1.2.2'

- name: expect failure with dep resolution failure
  command:  ansible-galaxy collection install fail_namespace.fail_collection -s {{ test_server }} {{ galaxy_verbosity }}
  register: fail_dep_mismatch
  failed_when: '"Cannot meet dependency requirement ''fail_dep2.name:<0.0.5'' for collection fail_namespace.fail_collection" not in fail_dep_mismatch.stderr'

- name: Find artifact url
  uri:
    url: '{{ test_server }}{{ vX }}collections/namespace3/name/versions/1.0.0/'
  register: artifact_url_response

- name: download a collection for an offline install - {{ test_name }}
  get_url:
    url: '{{ artifact_url_response.json.download_url }}'
    dest: '{{ galaxy_dir }}/namespace3.tar.gz'

- name: install a collection from a tarball - {{ test_name }}
  command: ansible-galaxy collection install '{{ galaxy_dir }}/namespace3.tar.gz' {{ galaxy_verbosity }}
  register: install_tarball
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'

- name: get result of install collection from a tarball - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace3/name/MANIFEST.json'
  register: install_tarball_actual

- name: assert install a collection from a tarball - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace3.name:1.0.0'' to" in install_tarball.stdout'
    - (install_tarball_actual.content | b64decode | from_json).collection_info.version == '1.0.0'

- name: setup bad tarball - {{ test_name }}
  script: build_bad_tar.py {{ galaxy_dir | quote }}

- name: fail to install a collection from a bad tarball - {{ test_name }}
  command: ansible-galaxy collection install '{{ galaxy_dir }}/suspicious-test-1.0.0.tar.gz' {{ galaxy_verbosity }}
  register: fail_bad_tar
  failed_when: fail_bad_tar.rc != 1 and "Cannot extract tar entry '../../outside.sh' as it will be placed outside the collection directory" not in fail_bad_tar.stderr
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'

- name: get result of failed collection install - {{ test_name }}
  stat:
    path: '{{ galaxy_dir }}/ansible_collections\suspicious'
  register: fail_bad_tar_actual

- name: assert result of failed collection install - {{ test_name }}
  assert:
    that:
    - not fail_bad_tar_actual.stat.exists

- name: Find artifact url
  uri:
    url: '{{ test_server }}{{ vX }}collections/namespace4/name/versions/1.0.0/'
  register: artifact_url_response

- name: install a collection from a URI - {{ test_name }}
  command: ansible-galaxy collection install {{ artifact_url_response.json.download_url}} {{ galaxy_verbosity }}
  register: install_uri
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'

- name: get result of install collection from a URI - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace4/name/MANIFEST.json'
  register: install_uri_actual

- name: assert install a collection from a URI - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace4.name:1.0.0'' to" in install_uri.stdout'
    - (install_uri_actual.content | b64decode | from_json).collection_info.version == '1.0.0'

- name: fail to install a collection with an undefined URL - {{ test_name }}
  command: ansible-galaxy collection install namespace5.name {{ galaxy_verbosity }}
  register: fail_undefined_server
  failed_when: '"No setting was provided for required configuration plugin_type: galaxy_server plugin: undefined" not in fail_undefined_server.stderr'
  environment:
    ANSIBLE_GALAXY_SERVER_LIST: undefined

- name: install a collection with an empty server list - {{ test_name }}
  command: ansible-galaxy collection install namespace5.name -s '{{ test_server }}' {{ galaxy_verbosity }}
  register: install_empty_server_list
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'
    ANSIBLE_GALAXY_SERVER_LIST: ''

- name: get result of a collection with an empty server list - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace5/name/MANIFEST.json'
  register: install_empty_server_list_actual

- name: assert install a collection with an empty server list - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace5.name:1.0.0'' to" in install_empty_server_list.stdout'
    - (install_empty_server_list_actual.content | b64decode | from_json).collection_info.version == '1.0.0'

- name: create test requirements file with both roles and collections - {{ test_name }}
  copy:
    content: |
      collections:
      - namespace6.name
      - name: namespace7.name
      roles:
      - skip.me
    dest: '{{ galaxy_dir }}/ansible_collections/requirements-with-role.yml'

# Need to run with -vvv to validate the roles will be skipped msg
- name: install collections only with requirements-with-role.yml - {{ test_name }}
  command: ansible-galaxy collection install -r '{{ galaxy_dir }}/ansible_collections/requirements-with-role.yml' -s '{{ test_server }}' -vvv
  register: install_req_collection
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'

- name: get result of install collections only with requirements-with-roles.yml - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
  register: install_req_collection_actual
  loop_control:
    loop_var: collection
  loop:
  - namespace6
  - namespace7

- name: assert install collections only with requirements-with-role.yml - {{ test_name }}
  assert:
    that:
    - '"contains roles which will be ignored" in install_req_collection.stdout'
    - '"Installing ''namespace6.name:1.0.0'' to" in install_req_collection.stdout'
    - '"Installing ''namespace7.name:1.0.0'' to" in install_req_collection.stdout'
    - (install_req_collection_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
    - (install_req_collection_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'

- name: create test requirements file with just collections - {{ test_name }}
  copy:
    content: |
      collections:
      - namespace8.name
      - name: namespace9.name
    dest: '{{ galaxy_dir }}/ansible_collections/requirements.yaml'

- name: install collections with ansible-galaxy install - {{ test_name }}
  command: ansible-galaxy install -r '{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_server }}'
  register: install_req
  environment:
    ANSIBLE_COLLECTIONS_PATH: '{{ galaxy_dir }}/ansible_collections'

- name: get result of install collections with ansible-galaxy install - {{ test_name }}
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name/MANIFEST.json'
  register: install_req_actual
  loop_control:
    loop_var: collection
  loop:
  - namespace8
  - namespace9

- name: assert install collections with ansible-galaxy install - {{ test_name }}
  assert:
    that:
    - '"Installing ''namespace8.name:1.0.0'' to" in install_req.stdout'
    - '"Installing ''namespace9.name:1.0.0'' to" in install_req.stdout'
    - (install_req_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
    - (install_req_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'

- name: remove test collection install directory - {{ test_name }}
  file:
    path: '{{ galaxy_dir }}/ansible_collections'
    state: absent

- name: install collection with symlink - {{ test_name }}
  command: ansible-galaxy collection install symlink.symlink -s '{{ test_server }}' {{ galaxy_verbosity }}
  environment:
    ANSIBLE_COLLECTIONS_PATHS: '{{ galaxy_dir }}/ansible_collections'
  register: install_symlink

- find:
    paths: '{{ galaxy_dir }}/ansible_collections/symlink/symlink'
    recurse: yes
    file_type: any

- name: get result of install collection with symlink - {{ test_name }}
  stat:
    path: '{{ galaxy_dir }}/ansible_collections/symlink/symlink/{{ path }}'
  register: install_symlink_actual
  loop_control:
    loop_var: path
  loop:
  - REÅDMÈ.md-link
  - docs/REÅDMÈ.md
  - plugins/REÅDMÈ.md
  - REÅDMÈ.md-outside-link
  - docs-link
  - docs-link/REÅDMÈ.md

- name: assert install collection with symlink - {{ test_name }}
  assert:
    that:
    - '"Installing ''symlink.symlink:1.0.0'' to" in install_symlink.stdout'
    - install_symlink_actual.results[0].stat.islnk
    - install_symlink_actual.results[0].stat.lnk_target == 'REÅDMÈ.md'
    - install_symlink_actual.results[1].stat.islnk
    - install_symlink_actual.results[1].stat.lnk_target == '../REÅDMÈ.md'
    - install_symlink_actual.results[2].stat.islnk
    - install_symlink_actual.results[2].stat.lnk_target == '../REÅDMÈ.md'
    - install_symlink_actual.results[3].stat.isreg
    - install_symlink_actual.results[4].stat.islnk
    - install_symlink_actual.results[4].stat.lnk_target == 'docs'
    - install_symlink_actual.results[5].stat.islnk
    - install_symlink_actual.results[5].stat.lnk_target == '../REÅDMÈ.md'