| 1 |
##### Updating collections with a new version constraint |
| 2 |
|
| 3 |
# No deps |
| 4 |
|
| 5 |
- name: reset installation directory |
| 6 |
file: |
| 7 |
state: "{{ item }}" |
| 8 |
path: "{{ galaxy_dir }}/ansible_collections" |
| 9 |
loop: |
| 10 |
- absent |
| 11 |
- directory |
| 12 |
|
| 13 |
- name: install a collection |
| 14 |
command: ansible-galaxy collection install namespace1.name1:0.0.1 {{ galaxy_verbosity }} |
| 15 |
register: result |
| 16 |
failed_when: |
| 17 |
- '"namespace1.name1:0.0.1 was installed successfully" not in result.stdout_lines' |
| 18 |
|
| 19 |
- name: install a new version of the collection without --force |
| 20 |
command: ansible-galaxy collection install namespace1.name1:>0.0.4,<=0.0.5 {{ galaxy_verbosity }} |
| 21 |
register: result |
| 22 |
|
| 23 |
- name: check the MANIFEST.json to verify the version |
| 24 |
slurp: |
| 25 |
path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json' |
| 26 |
register: metadata |
| 27 |
|
| 28 |
- assert: |
| 29 |
that: |
| 30 |
- '"namespace1.name1:0.0.5 was installed successfully" in result.stdout_lines' |
| 31 |
- (metadata.content | b64decode | from_json).collection_info.version == '0.0.5' |
| 32 |
|
| 33 |
- name: don't reinstall the collection in the requirement is compatible |
| 34 |
command: ansible-galaxy collection install namespace1.name1:>=0.0.5 {{ galaxy_verbosity }} |
| 35 |
register: result |
| 36 |
|
| 37 |
- assert: |
| 38 |
that: "\"Nothing to do. All requested collections are already installed.\" in result.stdout" |
| 39 |
|
| 40 |
- name: install a pre-release of the collection without --force |
| 41 |
command: ansible-galaxy collection install namespace1.name1:1.1.0-beta.1 {{ galaxy_verbosity }} |
| 42 |
register: result |
| 43 |
|
| 44 |
- name: check the MANIFEST.json to verify the version |
| 45 |
slurp: |
| 46 |
path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json' |
| 47 |
register: metadata |
| 48 |
|
| 49 |
- assert: |
| 50 |
that: |
| 51 |
- '"namespace1.name1:1.1.0-beta.1 was installed successfully" in result.stdout_lines' |
| 52 |
- (metadata.content | b64decode | from_json).collection_info.version == '1.1.0-beta.1' |
| 53 |
|
| 54 |
# With deps |
| 55 |
|
| 56 |
- name: reset installation directory |
| 57 |
file: |
| 58 |
state: "{{ item }}" |
| 59 |
path: "{{ galaxy_dir }}/ansible_collections" |
| 60 |
loop: |
| 61 |
- absent |
| 62 |
- directory |
| 63 |
|
| 64 |
- name: install a dep that will need to be upgraded to be compatible with the parent |
| 65 |
command: ansible-galaxy collection install child_dep.child_collection:0.4.0 --no-deps {{ galaxy_verbosity }} |
| 66 |
register: result |
| 67 |
failed_when: |
| 68 |
- '"child_dep.child_collection:0.4.0 was installed successfully" not in result.stdout_lines' |
| 69 |
|
| 70 |
- name: install a dep of the dep that will need to be upgraded to be compatible |
| 71 |
command: ansible-galaxy collection install child_dep.child_dep2:>1.2.2 {{ galaxy_verbosity }} |
| 72 |
register: result |
| 73 |
failed_when: |
| 74 |
- '"child_dep.child_dep2:1.2.3 was installed successfully" not in result.stdout_lines' |
| 75 |
|
| 76 |
- name: install the parent without deps to test dep reconciliation during upgrade |
| 77 |
command: ansible-galaxy collection install parent_dep.parent_collection:0.0.1 {{ galaxy_verbosity }} |
| 78 |
register: result |
| 79 |
failed_when: |
| 80 |
- '"parent_dep.parent_collection:0.0.1 was installed successfully" not in result.stdout_lines' |
| 81 |
|
| 82 |
- name: test upgrading the parent collection and dependencies |
| 83 |
command: ansible-galaxy collection install parent_dep.parent_collection:>=1.0.0,<1.1.0 {{ galaxy_verbosity }} |
| 84 |
register: result |
| 85 |
|
| 86 |
- name: check the MANIFEST.json to verify the versions |
| 87 |
slurp: |
| 88 |
path: '{{ galaxy_dir }}/ansible_collections/{{ item.namespace }}/{{ item.name }}/MANIFEST.json' |
| 89 |
register: metadata |
| 90 |
loop: |
| 91 |
- namespace: parent_dep |
| 92 |
name: parent_collection |
| 93 |
- namespace: child_dep |
| 94 |
name: child_collection |
| 95 |
- namespace: child_dep |
| 96 |
name: child_dep2 |
| 97 |
|
| 98 |
- assert: |
| 99 |
that: |
| 100 |
- '"parent_dep.parent_collection:1.0.0 was installed successfully" in result.stdout_lines' |
| 101 |
- (metadata.results[0].content | b64decode | from_json).collection_info.version == '1.0.0' |
| 102 |
- '"child_dep.child_collection:0.9.9 was installed successfully" in result.stdout_lines' |
| 103 |
- (metadata.results[1].content | b64decode | from_json).collection_info.version == '0.9.9' |
| 104 |
- '"child_dep.child_dep2:1.2.2 was installed successfully" in result.stdout_lines' |
| 105 |
- (metadata.results[2].content | b64decode | from_json).collection_info.version == '1.2.2' |
| 106 |
|
| 107 |
- name: test upgrading a collection only upgrades dependencies if necessary |
| 108 |
command: ansible-galaxy collection install parent_dep.parent_collection:1.1.0 {{ galaxy_verbosity }} |
| 109 |
register: result |
| 110 |
|
| 111 |
- name: check the MANIFEST.json to verify the versions |
| 112 |
slurp: |
| 113 |
path: '{{ galaxy_dir }}/ansible_collections/{{ item.namespace }}/{{ item.name }}/MANIFEST.json' |
| 114 |
register: metadata |
| 115 |
loop: |
| 116 |
- namespace: parent_dep |
| 117 |
name: parent_collection |
| 118 |
- namespace: child_dep |
| 119 |
name: child_collection |
| 120 |
- namespace: child_dep |
| 121 |
name: child_dep2 |
| 122 |
|
| 123 |
- assert: |
| 124 |
that: |
| 125 |
- '"parent_dep.parent_collection:1.1.0 was installed successfully" in result.stdout_lines' |
| 126 |
- (metadata.results[0].content | b64decode | from_json).collection_info.version == '1.1.0' |
| 127 |
- "\"'child_dep.child_collection:0.9.9' is already installed, skipping.\" in result.stdout_lines" |
| 128 |
- (metadata.results[1].content | b64decode | from_json).collection_info.version == '0.9.9' |
| 129 |
- "\"'child_dep.child_dep2:1.2.2' is already installed, skipping.\" in result.stdout_lines" |
| 130 |
- (metadata.results[2].content | b64decode | from_json).collection_info.version == '1.2.2' |
| 131 |
|
| 132 |
##### Updating collections with --upgrade |
| 133 |
|
| 134 |
# No deps |
| 135 |
|
| 136 |
- name: reset installation directory |
| 137 |
file: |
| 138 |
state: "{{ item }}" |
| 139 |
path: "{{ galaxy_dir }}/ansible_collections" |
| 140 |
loop: |
| 141 |
- absent |
| 142 |
- directory |
| 143 |
|
| 144 |
- name: install a collection |
| 145 |
command: ansible-galaxy collection install namespace1.name1==0.0.1 {{ galaxy_verbosity }} |
| 146 |
register: result |
| 147 |
failed_when: |
| 148 |
- '"namespace1.name1:0.0.1 was installed successfully" not in result.stdout_lines' |
| 149 |
|
| 150 |
- name: install a new version of the collection with --upgrade |
| 151 |
command: ansible-galaxy collection install namespace1.name1:<=0.0.5 --upgrade {{ galaxy_verbosity }} |
| 152 |
register: result |
| 153 |
|
| 154 |
- name: check the MANIFEST.json to verify the version |
| 155 |
slurp: |
| 156 |
path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json' |
| 157 |
register: metadata |
| 158 |
|
| 159 |
- assert: |
| 160 |
that: |
| 161 |
- '"namespace1.name1:0.0.5 was installed successfully" in result.stdout_lines' |
| 162 |
- (metadata.content | b64decode | from_json).collection_info.version == '0.0.5' |
| 163 |
|
| 164 |
- name: upgrade the collection |
| 165 |
command: ansible-galaxy collection install namespace1.name1:<0.0.7 -U {{ galaxy_verbosity }} |
| 166 |
register: result |
| 167 |
|
| 168 |
- assert: |
| 169 |
that: '"namespace1.name1:0.0.6 was installed successfully" in result.stdout_lines' |
| 170 |
|
| 171 |
- name: upgrade the collection to the last version excluding prereleases |
| 172 |
command: ansible-galaxy collection install namespace1.name1 -U {{ galaxy_verbosity }} |
| 173 |
register: result |
| 174 |
|
| 175 |
- assert: |
| 176 |
that: '"namespace1.name1:1.0.9 was installed successfully" in result.stdout_lines' |
| 177 |
|
| 178 |
- name: upgrade the collection to the latest available version including prereleases |
| 179 |
command: ansible-galaxy collection install namespace1.name1 --pre -U {{ galaxy_verbosity }} |
| 180 |
register: result |
| 181 |
|
| 182 |
- assert: |
| 183 |
that: '"namespace1.name1:1.1.0-beta.1 was installed successfully" in result.stdout_lines' |
| 184 |
|
| 185 |
- name: run the same command again |
| 186 |
command: ansible-galaxy collection install namespace1.name1 --pre -U {{ galaxy_verbosity }} |
| 187 |
register: result |
| 188 |
|
| 189 |
- assert: |
| 190 |
that: "\"'namespace1.name1:1.1.0-beta.1' is already installed, skipping.\" in result.stdout" |
| 191 |
|
| 192 |
# With deps |
| 193 |
|
| 194 |
- name: reset installation directory |
| 195 |
file: |
| 196 |
state: "{{ item }}" |
| 197 |
path: "{{ galaxy_dir }}/ansible_collections" |
| 198 |
loop: |
| 199 |
- absent |
| 200 |
- directory |
| 201 |
|
| 202 |
- name: install a parent collection and a particular version of its dependency |
| 203 |
command: ansible-galaxy collection install parent_dep.parent_collection:1.0.0 child_dep.child_collection:0.5.0 {{ galaxy_verbosity }} |
| 204 |
register: result |
| 205 |
failed_when: |
| 206 |
- '"parent_dep.parent_collection:1.0.0 was installed successfully" not in result.stdout_lines' |
| 207 |
- '"child_dep.child_collection:0.5.0 was installed successfully" not in result.stdout_lines' |
| 208 |
|
| 209 |
- name: upgrade the parent and child - the child's new version has a dependency that should be installed |
| 210 |
command: ansible-galaxy collection install parent_dep.parent_collection -U {{ galaxy_verbosity }} |
| 211 |
register: result |
| 212 |
|
| 213 |
- name: check the MANIFEST.json to verify the versions |
| 214 |
slurp: |
| 215 |
path: '{{ galaxy_dir }}/ansible_collections/{{ item.namespace }}/{{ item.name }}/MANIFEST.json' |
| 216 |
register: metadata |
| 217 |
loop: |
| 218 |
- namespace: parent_dep |
| 219 |
name: parent_collection |
| 220 |
- namespace: child_dep |
| 221 |
name: child_collection |
| 222 |
- namespace: child_dep |
| 223 |
name: child_dep2 |
| 224 |
|
| 225 |
- assert: |
| 226 |
that: |
| 227 |
- '"parent_dep.parent_collection:2.0.0 was installed successfully" in result.stdout_lines' |
| 228 |
- (metadata.results[0].content | b64decode | from_json).collection_info.version == '2.0.0' |
| 229 |
- '"child_dep.child_collection:1.0.0 was installed successfully" in result.stdout_lines' |
| 230 |
- (metadata.results[1].content | b64decode | from_json).collection_info.version == '1.0.0' |
| 231 |
- '"child_dep.child_dep2:1.2.2 was installed successfully" in result.stdout_lines' |
| 232 |
- (metadata.results[2].content | b64decode | from_json).collection_info.version == '1.2.2' |
| 233 |
|
| 234 |
# Test using a requirements.yml file for upgrade |
| 235 |
|
| 236 |
- name: reset installation directory |
| 237 |
file: |
| 238 |
state: "{{ item }}" |
| 239 |
path: "{{ galaxy_dir }}/ansible_collections" |
| 240 |
loop: |
| 241 |
- absent |
| 242 |
- directory |
| 243 |
|
| 244 |
- name: install upgradeable collections |
| 245 |
command: ansible-galaxy collection install namespace1.name1:1.0.0 parent_dep.parent_collection:0.0.1 {{ galaxy_verbosity }} |
| 246 |
register: result |
| 247 |
failed_when: |
| 248 |
- '"namespace1.name1:1.0.0 was installed successfully" not in result.stdout_lines' |
| 249 |
- '"parent_dep.parent_collection:0.0.1 was installed successfully" not in result.stdout_lines' |
| 250 |
- '"child_dep.child_collection:0.4.0 was installed successfully" not in result.stdout_lines' |
| 251 |
|
| 252 |
- name: create test requirements file with both roles and collections - {{ test_name }} |
| 253 |
copy: |
| 254 |
content: | |
| 255 |
collections: |
| 256 |
- namespace1.name1 |
| 257 |
- name: parent_dep.parent_collection |
| 258 |
version: <=2.0.0 |
| 259 |
roles: |
| 260 |
- skip.me |
| 261 |
dest: '{{ galaxy_dir }}/ansible_collections/requirements.yml' |
| 262 |
|
| 263 |
- name: upgrade collections with the requirements.yml |
| 264 |
command: ansible-galaxy collection install -r {{ requirements_path }} --upgrade {{ galaxy_verbosity }} |
| 265 |
vars: |
| 266 |
requirements_path: '{{ galaxy_dir }}/ansible_collections/requirements.yml' |
| 267 |
register: result |
| 268 |
|
| 269 |
- assert: |
| 270 |
that: |
| 271 |
- '"namespace1.name1:1.0.9 was installed successfully" in result.stdout_lines' |
| 272 |
- '"parent_dep.parent_collection:2.0.0 was installed successfully" in result.stdout_lines' |
| 273 |
- '"child_dep.child_collection:1.0.0 was installed successfully" in result.stdout_lines' |
| 274 |
- '"child_dep.child_dep2:1.2.2 was installed successfully" in result.stdout_lines' |
| 275 |
|
| 276 |
- name: cleanup |
| 277 |
file: |
| 278 |
state: "{{ item }}" |
| 279 |
path: "{{ galaxy_dir }}/ansible_collections" |
| 280 |
loop: |
| 281 |
- absent |
| 282 |
- directory |