Skip to content

Commit f66a40e

Browse files
authored
Merge pull request #171 from stackhpc/fix-publication-cleanup
Fix publication cleanup for multiple publications
2 parents 9c22add + 420de8f commit f66a40e

File tree

4 files changed

+69
-59
lines changed

4 files changed

+69
-59
lines changed

ansible/dev-pulp-repo-publication-cleanup.yml

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,7 @@
1616
pulp_username: "{{ dev_pulp_username }}"
1717
pulp_password: "{{ dev_pulp_password }}"
1818
tasks:
19-
- name: Query repositories
20-
pulp.squeezer.rpm_repository:
21-
pulp_url: "{{ pulp_url }}"
22-
username: "{{ pulp_username }}"
23-
password: "{{ pulp_password }}"
24-
register: pulp_repos_list
25-
26-
- name: Query publications
27-
pulp.squeezer.rpm_publication:
28-
pulp_url: "{{ pulp_url }}"
29-
username: "{{ pulp_username }}"
30-
password: "{{ pulp_password }}"
31-
register: pulp_pubs_list
32-
33-
- name: Query distributions
34-
pulp.squeezer.rpm_distribution:
35-
pulp_url: "{{ pulp_url }}"
36-
username: "{{ pulp_username }}"
37-
password: "{{ pulp_password }}"
38-
register: pulp_dists_list
39-
40-
- block:
41-
- name: Show duplicate publications
42-
debug:
43-
msg: "{{ pubs | sort(attribute='pulp_created') }}"
44-
loop: "{{ dev_pulp_distribution_rpm }}"
45-
loop_control:
46-
label: "{{ item.repository }}"
47-
when: pubs | length > 1
48-
49-
- name: Fail if duplicate publications have distributions
50-
assert:
51-
that: dists | length == 0
52-
loop: "{{ dev_pulp_distribution_rpm }}"
53-
loop_control:
54-
label: "{{ item.repository }}"
55-
when: pubs | length > 1
56-
vars:
57-
duplicate_pub: "{{ pubs | sort(attribute='pulp_created') | last }}"
58-
dists: "{{ pulp_dists_list.distributions | selectattr('publication', 'equalto', duplicate_pub.pulp_href) }}"
59-
60-
# Use URI module since pulp.squeezer.rpm_publication fails if there are
61-
# multiple matching publications.
62-
- name: Destroy duplicate publications
63-
uri:
64-
url: "{{ pulp_url }}{{ duplicate_pub.pulp_href }}"
65-
user: "{{ pulp_username }}"
66-
password: "{{ pulp_password }}"
67-
method: DELETE
68-
status_code: 204
69-
force_basic_auth: true
70-
loop: "{{ dev_pulp_distribution_rpm }}"
71-
loop_control:
72-
label: "{{ item.repository }}"
73-
when: pubs | length > 1
74-
vars:
75-
duplicate_pub: "{{ pubs | sort(attribute='pulp_created') | last }}"
19+
- import_role:
20+
name: pulp-rpm-publication-cleanup
7621
vars:
77-
repo: "{{ pulp_repos_list.repositories | selectattr('name', 'equalto', item.repository) | first }}"
78-
pubs: "{{ pulp_pubs_list.publications | selectattr('repository_version', 'equalto', repo.latest_version_href) }}"
22+
pulp_rpm_publication_cleanup_repos: "{{ dev_pulp_distribution_rpm | map(attribute='repository') | list }}"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
pulp_url: https://localhost:8080
3+
pulp_username: admin
4+
pulp_password:
5+
6+
# List of names of repositories to clean up publications in.
7+
pulp_rpm_publication_cleanup_repos: []
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Show duplicate publications
3+
debug:
4+
msg: "{{ pubs | sort(attribute='pulp_created') }}"
5+
6+
- name: Fail if duplicate publications have distributions
7+
assert:
8+
that: dists | length == 0
9+
loop: "{{ duplicate_pubs }}"
10+
loop_control:
11+
loop_var: duplicate_pub
12+
vars:
13+
duplicate_pubs: "{{ (pubs | sort(attribute='pulp_created'))[1:] }}"
14+
dists: "{{ pulp_dists_list.distributions | selectattr('publication', 'equalto', duplicate_pub.pulp_href) }}"
15+
16+
# Use URI module since pulp.squeezer.rpm_publication fails if there are
17+
# multiple matching publications.
18+
- name: Destroy duplicate publications
19+
uri:
20+
url: "{{ pulp_url }}{{ duplicate_pub.pulp_href }}"
21+
user: "{{ pulp_username }}"
22+
password: "{{ pulp_password }}"
23+
method: DELETE
24+
status_code: 204
25+
force_basic_auth: true
26+
loop: "{{ duplicate_pubs }}"
27+
loop_control:
28+
loop_var: duplicate_pub
29+
vars:
30+
duplicate_pubs: "{{ (pubs | sort(attribute='pulp_created'))[1:] }}"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Query repositories
3+
pulp.squeezer.rpm_repository:
4+
pulp_url: "{{ pulp_url }}"
5+
username: "{{ pulp_username }}"
6+
password: "{{ pulp_password }}"
7+
register: pulp_repos_list
8+
9+
- name: Query publications
10+
pulp.squeezer.rpm_publication:
11+
pulp_url: "{{ pulp_url }}"
12+
username: "{{ pulp_username }}"
13+
password: "{{ pulp_password }}"
14+
register: pulp_pubs_list
15+
16+
- name: Query distributions
17+
pulp.squeezer.rpm_distribution:
18+
pulp_url: "{{ pulp_url }}"
19+
username: "{{ pulp_username }}"
20+
password: "{{ pulp_password }}"
21+
register: pulp_dists_list
22+
23+
- name: Destroy duplicate publications
24+
include_tasks: destroy-pubs.yml
25+
loop: "{{ pulp_rpm_publication_cleanup_repos }}"
26+
when: pubs | length > 1
27+
vars:
28+
repo: "{{ pulp_repos_list.repositories | selectattr('name', 'equalto', item) | first }}"
29+
pubs: "{{ pulp_pubs_list.publications | selectattr('repository_version', 'equalto', repo.latest_version_href) }}"

0 commit comments

Comments
 (0)