| 1 |
- name: initialize dev collection structure |
| 2 |
command: ansible-galaxy collection init {{ item }} --init-path "{{ galaxy_dir }}/dev/ansible_collections" {{ galaxy_verbosity }} |
| 3 |
loop: |
| 4 |
- 'dev.collection1' |
| 5 |
- 'dev.collection2' |
| 6 |
- 'dev.collection3' |
| 7 |
- 'dev.collection4' |
| 8 |
- 'dev.collection5' |
| 9 |
- 'dev.collection6' |
| 10 |
|
| 11 |
- name: initialize prod collection structure |
| 12 |
command: ansible-galaxy collection init {{ item }} --init-path "{{ galaxy_dir }}/prod/ansible_collections" {{ galaxy_verbosity }} |
| 13 |
loop: |
| 14 |
- 'prod.collection1' |
| 15 |
- 'prod.collection2' |
| 16 |
- 'prod.collection3' |
| 17 |
|
| 18 |
- name: Check that list warns on improperly named directories |
| 19 |
vars: |
| 20 |
wrong_name: nottherightname |
| 21 |
doc_fqcn: dev.collection1 |
| 22 |
dir_fqcn: dev.{{ wrong_name }} |
| 23 |
srcdir: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection1" |
| 24 |
destdir: "{{ galaxy_dir }}/dev/ansible_collections/dev/{{ wrong_name }}" |
| 25 |
block: |
| 26 |
- name: move dev.collection1 somewhere |
| 27 |
command: mv {{ srcdir }} {{ destdir }} |
| 28 |
|
| 29 |
- name: List dev collections |
| 30 |
command: ansible-galaxy collection list |
| 31 |
register: errant_directory_list |
| 32 |
environment: |
| 33 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev" |
| 34 |
|
| 35 |
- debug: var=errant_directory_list |
| 36 |
- assert: |
| 37 |
that: |
| 38 |
- errant_directory_list is success |
| 39 |
- errant_directory_list.rc == 0 |
| 40 |
- warning_text in errant_directory_list.stderr |
| 41 |
- dir_fqcn in errant_directory_list.stdout |
| 42 |
vars: |
| 43 |
warning_text: Collection at {{ destdir }} documents incorrect FQCN '{{ doc_fqcn }}' |
| 44 |
|
| 45 |
- name: List incorrect collection by metadataname |
| 46 |
command: ansible-galaxy collection list {{ doc_fqcn }} |
| 47 |
environment: |
| 48 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev" |
| 49 |
register: list_metadata_name |
| 50 |
|
| 51 |
- assert: |
| 52 |
that: |
| 53 |
- list_metadata_name is success |
| 54 |
- list_metadata_name.rc == 0 |
| 55 |
- doc_fqcn not in list_metadata_name.stdout |
| 56 |
|
| 57 |
- name: List incorrect collection by dirname |
| 58 |
command: ansible-galaxy collection list {{ dir_fqcn }} |
| 59 |
environment: |
| 60 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev" |
| 61 |
register: list_dir_name |
| 62 |
|
| 63 |
- assert: |
| 64 |
that: |
| 65 |
- list_dir_name is success |
| 66 |
- list_dir_name.rc == 0 |
| 67 |
- doc_fqcn not in list_dir_name.stdout |
| 68 |
- dir_fqcn in list_dir_name.stdout |
| 69 |
- warning_text in list_dir_name.stderr |
| 70 |
vars: |
| 71 |
warning_text: Collection at {{ destdir }} documents incorrect FQCN '{{ doc_fqcn }}' |
| 72 |
|
| 73 |
- name: move {{ doc_fqcn }} back |
| 74 |
command: mv {{ destdir }} {{ srcdir }} |
| 75 |
|
| 76 |
- name: replace the default version of the collections |
| 77 |
lineinfile: |
| 78 |
path: "{{ galaxy_dir }}/dev/ansible_collections/dev/{{ item.name }}/galaxy.yml" |
| 79 |
line: "{{ item.version }}" |
| 80 |
regexp: "version: .*" |
| 81 |
loop: |
| 82 |
- name: "collection1" |
| 83 |
version: "version: null" |
| 84 |
- name: "collection2" |
| 85 |
version: "version: placeholder" |
| 86 |
- name: "collection3" |
| 87 |
version: "version: ''" |
| 88 |
|
| 89 |
- name: set the namespace, name, and version keys to None |
| 90 |
lineinfile: |
| 91 |
path: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection4/galaxy.yml" |
| 92 |
line: "{{ item.after }}" |
| 93 |
regexp: "{{ item.before }}" |
| 94 |
loop: |
| 95 |
- before: "^namespace: dev" |
| 96 |
after: "namespace:" |
| 97 |
- before: "^name: collection4" |
| 98 |
after: "name:" |
| 99 |
- before: "^version: 1.0.0" |
| 100 |
after: "version:" |
| 101 |
|
| 102 |
- name: replace galaxy.yml content with a string |
| 103 |
copy: |
| 104 |
content: "invalid" |
| 105 |
dest: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection5/galaxy.yml" |
| 106 |
|
| 107 |
- name: remove galaxy.yml key required by build |
| 108 |
lineinfile: |
| 109 |
path: "{{ galaxy_dir }}/dev/ansible_collections/dev/collection6/galaxy.yml" |
| 110 |
line: "version: 1.0.0" |
| 111 |
state: absent |
| 112 |
|
| 113 |
- name: list collections in development without semver versions |
| 114 |
command: ansible-galaxy collection list {{ galaxy_verbosity }} |
| 115 |
register: list_result |
| 116 |
environment: |
| 117 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 118 |
|
| 119 |
- assert: |
| 120 |
that: |
| 121 |
- 'list_result.stdout is regex "dev.collection1\s+\*"' |
| 122 |
# Note the version displayed is the 'placeholder' string rather than "*" since it is not falsey |
| 123 |
- 'list_result.stdout is regex "dev.collection2\s+placeholder"' |
| 124 |
- 'list_result.stdout is regex "dev.collection3\s+\*"' |
| 125 |
- 'list_result.stdout is regex "dev.collection4\s+\*"' |
| 126 |
- 'list_result.stdout is regex "dev.collection5\s+\*"' |
| 127 |
- 'list_result.stdout is regex "dev.collection6\s+\*"' |
| 128 |
- 'list_result.stdout is not regex "ansible._protomatter\s+.*"' |
| 129 |
|
| 130 |
- name: list collections in human format |
| 131 |
command: ansible-galaxy collection list --format human |
| 132 |
register: list_result_human |
| 133 |
environment: |
| 134 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 135 |
|
| 136 |
- assert: |
| 137 |
that: |
| 138 |
- 'list_result_human.stdout is regex "dev.collection1\s+\*"' |
| 139 |
# Note the version displayed is the 'placeholder' string rather than "*" since it is not falsey |
| 140 |
- 'list_result_human.stdout is regex "dev.collection2\s+placeholder"' |
| 141 |
- 'list_result_human.stdout is regex "dev.collection3\s+\*"' |
| 142 |
- 'list_result_human.stdout is regex "dev.collection4\s+\*"' |
| 143 |
- 'list_result_human.stdout is regex "dev.collection5\s+\*"' |
| 144 |
- 'list_result_human.stdout is regex "dev.collection6\s+\*"' |
| 145 |
|
| 146 |
- name: list collections in yaml format |
| 147 |
command: ansible-galaxy collection list --format yaml |
| 148 |
register: list_result_yaml |
| 149 |
environment: |
| 150 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 151 |
|
| 152 |
- assert: |
| 153 |
that: |
| 154 |
- yaml_result[galaxy_dir ~ '/dev/ansible_collections'] != yaml_result[galaxy_dir ~ '/prod/ansible_collections'] |
| 155 |
vars: |
| 156 |
yaml_result: '{{ list_result_yaml.stdout | from_yaml }}' |
| 157 |
|
| 158 |
- assert: |
| 159 |
that: |
| 160 |
- "item.value | length == 6" |
| 161 |
- "item.value['dev.collection1'].version == '*'" |
| 162 |
- "item.value['dev.collection2'].version == 'placeholder'" |
| 163 |
- "item.value['dev.collection3'].version == '*'" |
| 164 |
- "item.value['dev.collection5'].version == '*'" |
| 165 |
- "item.value['dev.collection6'].version == '*'" |
| 166 |
with_dict: "{{ list_result_yaml.stdout | from_yaml }}" |
| 167 |
when: "'dev' in item.key" |
| 168 |
|
| 169 |
- name: list collections in json format |
| 170 |
command: ansible-galaxy collection list --format json |
| 171 |
register: list_result_json |
| 172 |
environment: |
| 173 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 174 |
|
| 175 |
- assert: |
| 176 |
that: |
| 177 |
- "item.value | length == 6" |
| 178 |
- "item.value['dev.collection1'].version == '*'" |
| 179 |
- "item.value['dev.collection2'].version == 'placeholder'" |
| 180 |
- "item.value['dev.collection3'].version == '*'" |
| 181 |
- "item.value['dev.collection5'].version == '*'" |
| 182 |
- "item.value['dev.collection6'].version == '*'" |
| 183 |
with_dict: "{{ list_result_json.stdout | from_json }}" |
| 184 |
when: "'dev' in item.key" |
| 185 |
|
| 186 |
- name: list single collection in json format |
| 187 |
command: "ansible-galaxy collection list {{ item.key }} --format json" |
| 188 |
register: list_single_result_json |
| 189 |
environment: |
| 190 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 191 |
with_dict: "{{ { 'dev.collection1': '*', 'dev.collection2': 'placeholder', 'dev.collection3': '*' } }}" |
| 192 |
|
| 193 |
- assert: |
| 194 |
that: |
| 195 |
- "(item.stdout | from_json)[galaxy_dir + '/dev/ansible_collections'][item.item.key].version == item.item.value" |
| 196 |
with_items: "{{ list_single_result_json.results }}" |
| 197 |
|
| 198 |
- name: list single collection in yaml format |
| 199 |
command: "ansible-galaxy collection list {{ item.key }} --format yaml" |
| 200 |
register: list_single_result_yaml |
| 201 |
environment: |
| 202 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 203 |
with_dict: "{{ { 'dev.collection1': '*', 'dev.collection2': 'placeholder', 'dev.collection3': '*' } }}" |
| 204 |
|
| 205 |
- assert: |
| 206 |
that: |
| 207 |
- "(item.stdout | from_yaml)[galaxy_dir + '/dev/ansible_collections'][item.item.key].version == item.item.value" |
| 208 |
with_items: "{{ list_single_result_json.results }}" |
| 209 |
|
| 210 |
- name: test that no json is emitted when no collection paths are usable |
| 211 |
command: "ansible-galaxy collection list --format json" |
| 212 |
register: list_result_error |
| 213 |
environment: |
| 214 |
ANSIBLE_COLLECTIONS_PATH: "i_dont_exist" |
| 215 |
|
| 216 |
- name: Ensure we get the expected warning |
| 217 |
assert: |
| 218 |
that: |
| 219 |
- "'{}' in list_result_error.stdout" |
| 220 |
- "'None of the provided paths were usable' in list_result_error.stderr" |
| 221 |
|
| 222 |
- name: install an artifact to the second collections path |
| 223 |
command: ansible-galaxy collection install namespace1.name1 -s galaxy_ng {{ galaxy_verbosity }} -p "{{ galaxy_dir }}/prod" |
| 224 |
environment: |
| 225 |
ANSIBLE_CONFIG: '{{ galaxy_dir }}/ansible.cfg' |
| 226 |
|
| 227 |
- name: replace the artifact version |
| 228 |
lineinfile: |
| 229 |
path: "{{ galaxy_dir }}/prod/ansible_collections/namespace1/name1/MANIFEST.json" |
| 230 |
line: ' "version": null,' |
| 231 |
regexp: ' "version": .*' |
| 232 |
|
| 233 |
- name: test listing collections in all paths |
| 234 |
command: ansible-galaxy collection list {{ galaxy_verbosity }} |
| 235 |
register: list_result |
| 236 |
ignore_errors: True |
| 237 |
environment: |
| 238 |
ANSIBLE_COLLECTIONS_PATH: "{{ galaxy_dir }}/dev:{{ galaxy_dir }}/prod" |
| 239 |
|
| 240 |
- assert: |
| 241 |
that: |
| 242 |
- list_result is failed |
| 243 |
- "'is expected to have a valid SemVer version value but got None' in list_result.stderr" |