|
| 1 | +--- |
| 2 | +- name: Query source repository |
| 3 | + uri: |
| 4 | + url: "{{ pulp_url }}/pulp/api/v3/repositories/container/container{% if item.src_is_push | default(false) | bool %}-push{% endif %}/?name={{ item.src_repo | urlencode | regex_replace('/','%2F') }}" |
| 5 | + user: "{{ pulp_username }}" |
| 6 | + password: "{{ pulp_password }}" |
| 7 | + method: GET |
| 8 | + status_code: 200 |
| 9 | + force_basic_auth: true |
| 10 | + register: src_repo |
| 11 | + when: item.state | default != 'absent' |
| 12 | + |
| 13 | +- name: Assert that source repository exists |
| 14 | + assert: |
| 15 | + that: |
| 16 | + src_repo.json.results | length > 0 |
| 17 | + when: item.state | default != 'absent' |
| 18 | + |
| 19 | +- name: Query destination repository |
| 20 | + uri: |
| 21 | + url: "{{ pulp_url }}/pulp/api/v3/repositories/container/container/?name={{ item.dest_repo | urlencode | regex_replace('/','%2F') }}" |
| 22 | + user: "{{ pulp_username }}" |
| 23 | + password: "{{ pulp_password }}" |
| 24 | + method: GET |
| 25 | + status_code: 200 |
| 26 | + force_basic_auth: true |
| 27 | + register: dest_repo |
| 28 | + |
| 29 | +- name: Assert that destination repository exists |
| 30 | + assert: |
| 31 | + that: |
| 32 | + dest_repo.json.results | length > 0 |
| 33 | + |
| 34 | +- name: Query tags |
| 35 | + uri: |
| 36 | + url: "{{ pulp_url }}/pulp/api/v3/content/container/tags/?name__in={{ item.tags | join(',') | urlencode | regex_replace('/','%2F') }}&repository_version={{ repo.json.results[0].latest_version_href | urlencode | regex_replace('/','%2F') }}" |
| 37 | + user: "{{ pulp_username }}" |
| 38 | + password: "{{ pulp_password }}" |
| 39 | + method: GET |
| 40 | + status_code: 200 |
| 41 | + force_basic_auth: true |
| 42 | + register: tags |
| 43 | + vars: |
| 44 | + repo: "{{ src_repo if item.state | default != 'absent' else dest_repo }}" |
| 45 | + |
| 46 | +# NOTE: Currently we don't verify that all tags exist. This can be fixed when we specify a different tag for each repo. |
| 47 | + |
| 48 | +- name: Add or remove content units |
| 49 | + uri: |
| 50 | + url: "{{ pulp_url }}{{ dest_repo.json.results[0].pulp_href }}{% if item.state | default != 'absent' %}add{% else %}remove{% endif %}/" |
| 51 | + user: "{{ pulp_username }}" |
| 52 | + password: "{{ pulp_password }}" |
| 53 | + method: POST |
| 54 | + status_code: 202 |
| 55 | + force_basic_auth: true |
| 56 | + body: |
| 57 | + content_units: "{{ tags.json.results | map(attribute='pulp_href') | list }}" |
| 58 | + body_format: json |
| 59 | + register: task |
| 60 | + |
| 61 | +- name: Wait for task to complete |
| 62 | + uri: |
| 63 | + url: "{{ pulp_url }}{{ task.json.task }}" |
| 64 | + user: "{{ pulp_username }}" |
| 65 | + password: "{{ pulp_password }}" |
| 66 | + method: GET |
| 67 | + status_code: 200 |
| 68 | + force_basic_auth: true |
| 69 | + register: result |
| 70 | + until: result.json.state not in ['waiting', 'running'] |
| 71 | + retries: 30 |
| 72 | + delay: 2 |
| 73 | + failed_when: result.json.state != 'completed' |
0 commit comments