Skip to content

Commit c6b3583

Browse files
committed
Allow skipping creation of existing distributions
1 parent 1428343 commit c6b3583

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

roles/pulp_distribution/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Role variables
1111
* `pulp_password`: Password used to access Pulp server. Default is unse
1212
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
1313
* `pulp_distribution_rpm`: List of distributions for RPM repositories. Default is an empty list
14+
* `pulp_distribution_rpm_skip_existing`: Whether to skip existing RPM
15+
distributions. If true, new distributions will not be created for a
16+
publication if any distributions exist for the same publication.
17+
Default is `false`.
1418

1519
Example playbook
1620
----------------

roles/pulp_distribution/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ pulp_password:
55
pulp_validate_certs: true
66

77
pulp_distribution_rpm: []
8+
9+
# Whether to skip existing RPM distributions. If true, new distributions will
10+
# not be created for a publication if any distributions exist for the same
11+
# publication.
12+
pulp_distribution_rpm_skip_existing: false

roles/pulp_distribution/tasks/rpm.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
validate_certs: "{{ pulp_validate_certs | bool }}"
1616
register: pulp_pubs_list
1717

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+
1826
- name: Ensure RPM distributions are defined
1927
vars:
2028
repo: "{{ pulp_repos_list.repositories | selectattr('name', 'equalto', item.repository) | first }}"
@@ -23,13 +31,18 @@
2331
# If the distribution uses the latest version:
2432
latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | sort(attribute='repository_version', reverse=True) }}"
2533
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 }}"
2636
pulp.squeezer.rpm_distribution:
2737
pulp_url: "{{ pulp_url }}"
2838
username: "{{ pulp_username }}"
2939
password: "{{ pulp_password }}"
3040
validate_certs: "{{ pulp_validate_certs | bool }}"
3141
name: "{{ item.name }}"
3242
base_path: "{{ item.base_path }}"
33-
publication: "{{ pub.pulp_href }}"
43+
publication: "{{ pub.pulp_href if item.state == 'present' else omit }}"
3444
state: "{{ item.state }}"
3545
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

Comments
 (0)