|
15 | 15 | validate_certs: "{{ pulp_validate_certs | bool }}" |
16 | 16 | register: pulp_pubs_list |
17 | 17 |
|
| 18 | +- name: Query distributions |
| 19 | + pulp.squeezer.rpm_distribution: |
| 20 | + pulp_url: "{{ pulp_url }}" |
| 21 | + username: "{{ pulp_username }}" |
| 22 | + password: "{{ pulp_password }}" |
| 23 | + validate_certs: "{{ pulp_validate_certs | bool }}" |
| 24 | + register: pulp_dists_list |
| 25 | + |
18 | 26 | - name: Ensure RPM distributions are defined |
19 | 27 | vars: |
20 | 28 | repo: "{{ pulp_repos_list.repositories | selectattr('name', 'equalto', item.repository) | first }}" |
|
23 | 31 | # If the distribution uses the latest version: |
24 | 32 | latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | sort(attribute='repository_version', reverse=True) }}" |
25 | 33 | pub: "{{ latest_pub | first if item.version is not defined else specific_pub | first }}" |
| 34 | + # Whether any distributions exist for this publication. |
| 35 | + pub_has_dists: "{{ pulp_dists_list.distributions | selectattr('publication', 'equalto', pub.pulp_href) | list | length > 0 }}" |
26 | 36 | pulp.squeezer.rpm_distribution: |
27 | 37 | pulp_url: "{{ pulp_url }}" |
28 | 38 | username: "{{ pulp_username }}" |
29 | 39 | password: "{{ pulp_password }}" |
30 | 40 | validate_certs: "{{ pulp_validate_certs | bool }}" |
31 | 41 | name: "{{ item.name }}" |
32 | 42 | base_path: "{{ item.base_path }}" |
33 | | - publication: "{{ pub.pulp_href }}" |
| 43 | + publication: "{{ pub.pulp_href if item.state == 'present' else omit }}" |
34 | 44 | state: "{{ item.state }}" |
35 | 45 | with_items: "{{ pulp_distribution_rpm }}" |
| 46 | + when: >- |
| 47 | + item.state == 'absent' or |
| 48 | + not (item.skip_existing | default(pulp_distribution_rpm_skip_existing) | bool and pub_has_dists) |
0 commit comments