| 1 |
- name: test tarfile dependency resolution without querying distribution servers |
| 2 |
vars: |
| 3 |
init_dir: "{{ galaxy_dir }}/offline/setup" |
| 4 |
build_dir: "{{ galaxy_dir }}/offline/build" |
| 5 |
install_dir: "{{ galaxy_dir }}/offline/collections" |
| 6 |
block: |
| 7 |
- name: create test directories |
| 8 |
file: |
| 9 |
path: "{{ item }}" |
| 10 |
state: directory |
| 11 |
loop: |
| 12 |
- "{{ init_dir }}" |
| 13 |
- "{{ build_dir }}" |
| 14 |
- "{{ install_dir }}" |
| 15 |
|
| 16 |
- name: initialize two collections |
| 17 |
command: ansible-galaxy collection init ns.{{ item }} --init-path {{ init_dir }} |
| 18 |
loop: |
| 19 |
- coll1 |
| 20 |
- coll2 |
| 21 |
|
| 22 |
- name: add one collection as the dependency of the other |
| 23 |
lineinfile: |
| 24 |
path: "{{ galaxy_dir }}/offline/setup/ns/coll1/galaxy.yml" |
| 25 |
regexp: "^dependencies:*" |
| 26 |
line: "dependencies: {'ns.coll2': '>=1.0.0'}" |
| 27 |
|
| 28 |
- name: create required runtime.yml |
| 29 |
copy: |
| 30 |
dest: "{{ galaxy_dir }}/offline/setup/ns/{{ item }}/meta/runtime.yml" |
| 31 |
content: "requires_ansible: '>=1.0.0'" |
| 32 |
loop: |
| 33 |
- coll1 |
| 34 |
- coll2 |
| 35 |
|
| 36 |
- name: build both collections |
| 37 |
command: ansible-galaxy collection build {{ init_dir }}/ns/{{ item }} |
| 38 |
args: |
| 39 |
chdir: "{{ build_dir }}" |
| 40 |
loop: |
| 41 |
- coll1 |
| 42 |
- coll2 |
| 43 |
|
| 44 |
- name: install the dependency from the tarfile |
| 45 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll2-1.0.0.tar.gz -p {{ install_dir }} -s offline |
| 46 |
|
| 47 |
- name: install the tarfile with the installed dependency |
| 48 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll1-1.0.0.tar.gz -p {{ install_dir }} -s offline |
| 49 |
|
| 50 |
- name: empty the installed collections directory |
| 51 |
file: |
| 52 |
path: "{{ install_dir }}" |
| 53 |
state: "{{ item }}" |
| 54 |
loop: |
| 55 |
- absent |
| 56 |
- directory |
| 57 |
|
| 58 |
- name: edit skeleton with new versions to test upgrading |
| 59 |
lineinfile: |
| 60 |
path: "{{ galaxy_dir }}/offline/setup/ns/{{ item }}/galaxy.yml" |
| 61 |
regexp: "^version:.*$" |
| 62 |
line: "version: 2.0.0" |
| 63 |
loop: |
| 64 |
- coll1 |
| 65 |
- coll2 |
| 66 |
|
| 67 |
- name: build the tarfiles to test upgrading |
| 68 |
command: ansible-galaxy collection build {{ init_dir }}/ns/{{ item }} |
| 69 |
args: |
| 70 |
chdir: "{{ build_dir }}" |
| 71 |
loop: |
| 72 |
- coll1 |
| 73 |
- coll2 |
| 74 |
|
| 75 |
- name: install the tarfile and its dep with an unreachable server (expected error) |
| 76 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll1-1.0.0.tar.gz -p {{ install_dir }} -s offline |
| 77 |
environment: |
| 78 |
ANSIBLE_FORCE_COLOR: False |
| 79 |
ANSIBLE_NOCOLOR: True |
| 80 |
ignore_errors: yes |
| 81 |
register: missing_dep |
| 82 |
|
| 83 |
- name: install the tarfile with a missing dependency and --offline |
| 84 |
command: ansible-galaxy collection install --offline {{ build_dir }}/ns-coll1-1.0.0.tar.gz -p {{ install_dir }} -s offline |
| 85 |
environment: |
| 86 |
ANSIBLE_FORCE_COLOR: False |
| 87 |
ANSIBLE_NOCOLOR: True |
| 88 |
ignore_errors: yes |
| 89 |
register: missing_dep_offline |
| 90 |
|
| 91 |
- assert: |
| 92 |
that: |
| 93 |
- missing_dep.failed |
| 94 |
- missing_dep_offline.failed |
| 95 |
- galaxy_err in missing_dep.stderr |
| 96 |
- missing_err in missing_dep_offline.stderr |
| 97 |
vars: |
| 98 |
galaxy_err: "Unknown error when attempting to call Galaxy at '{{ offline_server }}'" |
| 99 |
missing_err: |- |
| 100 |
Failed to resolve the requested dependencies map. Could not satisfy the following requirements: |
| 101 |
* ns.coll2:>=1.0.0 (dependency of ns.coll1:1.0.0) |
| 102 |
|
| 103 |
- name: install the dependency from the tarfile |
| 104 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll2-1.0.0.tar.gz -p {{ install_dir }} |
| 105 |
|
| 106 |
- name: install the tarfile with --offline for dep resolution |
| 107 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll1-1.0.0.tar.gz {{ cli_opts }} |
| 108 |
vars: |
| 109 |
cli_opts: "--offline -p {{ install_dir }} -s offline" |
| 110 |
register: offline_install |
| 111 |
|
| 112 |
- name: upgrade using tarfile with --offline for dep resolution |
| 113 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll1-2.0.0.tar.gz {{ cli_opts }} |
| 114 |
vars: |
| 115 |
cli_opts: "--offline --upgrade -p {{ install_dir }} -s offline" |
| 116 |
register: offline_upgrade |
| 117 |
|
| 118 |
- name: reinstall ns-coll1-1.0.0 to test upgrading the dependency too |
| 119 |
command: ansible-galaxy collection install {{ build_dir }}/ns-coll1-1.0.0.tar.gz {{ cli_opts }} |
| 120 |
vars: |
| 121 |
cli_opts: "--offline --force -p {{ install_dir }} -s offline" |
| 122 |
|
| 123 |
- name: upgrade both collections using tarfiles and --offline |
| 124 |
command: ansible-galaxy collection install {{ collections }} {{ cli_opts }} |
| 125 |
vars: |
| 126 |
collections: "{{ build_dir }}/ns-coll1-2.0.0.tar.gz {{ build_dir }}/ns-coll2-2.0.0.tar.gz" |
| 127 |
cli_opts: "--offline --upgrade -s offline" |
| 128 |
register: upgrade_all |
| 129 |
|
| 130 |
- assert: |
| 131 |
that: |
| 132 |
- '"ns.coll1:1.0.0 was installed successfully" in offline_install.stdout' |
| 133 |
- '"ns.coll1:2.0.0 was installed successfully" in offline_upgrade.stdout' |
| 134 |
- '"ns.coll1:2.0.0 was installed successfully" in upgrade_all.stdout' |
| 135 |
- '"ns.coll2:2.0.0 was installed successfully" in upgrade_all.stdout' |
| 136 |
|
| 137 |
always: |
| 138 |
- name: clean up test directories |
| 139 |
file: |
| 140 |
path: "{{ item }}" |
| 141 |
state: absent |
| 142 |
loop: |
| 143 |
- "{{ init_dir }}" |
| 144 |
- "{{ build_dir }}" |
| 145 |
- "{{ install_dir }}" |