Skip to content

Commit 842d724

Browse files
authored
Merge pull request #21 from stackhpc/deb-pub-dist
Add deb support in pulp_distribution and pulp_publication roles
2 parents 2e540de + 98b032e commit 842d724

File tree

9 files changed

+108
-6
lines changed

9 files changed

+108
-6
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ Tested with the current Ansible 2.9-2.10 releases.
1111

1212
## Included content
1313

14-
Roles:
15-
16-
* `pulp_repository`
17-
* `pulp_publication`
18-
* `pulp_distribution`
14+
pulp_repository role
1915

2016
## Using this collection
2117

roles/pulp_distribution/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ 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_container`: List of distributions for container repositories. Default is an empty list
14+
* `pulp_distribution_deb`: List of distributions for Deb repositories. Default is an empty list
1415
* `pulp_distribution_rpm`: List of distributions for RPM repositories. Default is an empty list
16+
* `pulp_distribution_deb_skip_existing`: Whether to skip existing Deb
17+
distributions. If true, new distributions will not be created for a
18+
publication if any distributions exist for the same publication.
19+
Default is `false`.
1520
* `pulp_distribution_rpm_skip_existing`: Whether to skip existing RPM
1621
distributions. If true, new distributions will not be created for a
1722
publication if any distributions exist for the same publication.
@@ -43,6 +48,23 @@ Example playbook
4348
repository: pulp/pulp
4449
version: 2
4550
state: present
51+
pulp_distribution_deb:
52+
# Distribute the latest version of the ubuntu-focal repository.
53+
- name: ubuntu-focal
54+
base_path: ubuntu-focal
55+
repository: ubuntu-focal
56+
state: present
57+
# Distribute version 2 of the ubuntu-focal-security repository.
58+
- name: ubuntu-focal-security
59+
base_path: ubuntu-focal-security
60+
repository: ubuntu-focal-security
61+
version: 2
62+
state: present
63+
# Distribute the same publication as the ubuntu-focal distribution.
64+
- name: ubuntu-focal-production
65+
base_path: ubuntu-focal-production
66+
distribution: ubuntu-focal
67+
state: present
4668
pulp_distribution_rpm:
4769
# Distribute the latest version of the centos-baseos repository.
4870
- name: centos-baseos

roles/pulp_distribution/defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ pulp_password:
55
pulp_validate_certs: true
66

77
pulp_distribution_container: []
8+
pulp_distribution_deb: []
89
pulp_distribution_rpm: []
910

10-
# Whether to skip existing RPM distributions. If true, new distributions will
11+
# Whether to skip existing distributions. If true, new distributions will
1112
# not be created for a publication if any distributions exist for the same
1213
# publication.
14+
pulp_distribution_deb_skip_existing: false
1315
pulp_distribution_rpm_skip_existing: false
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
- name: Query repositories
3+
pulp.squeezer.deb_repository:
4+
pulp_url: "{{ pulp_url }}"
5+
username: "{{ pulp_username }}"
6+
password: "{{ pulp_password }}"
7+
validate_certs: "{{ pulp_validate_certs | bool }}"
8+
register: pulp_repos_list
9+
10+
- name: Query publications
11+
pulp.squeezer.deb_publication:
12+
pulp_url: "{{ pulp_url }}"
13+
username: "{{ pulp_username }}"
14+
password: "{{ pulp_password }}"
15+
validate_certs: "{{ pulp_validate_certs | bool }}"
16+
register: pulp_pubs_list
17+
18+
- name: Query distributions
19+
pulp.squeezer.deb_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+
26+
- name: Ensure Deb distributions are defined
27+
vars:
28+
repo: "{{ pulp_repos_list.repositories | selectattr('name', 'equalto', item.repository) | first }}"
29+
# If the distribution references a specific version:
30+
specific_pub: "{{ pulp_pubs_list.publications | selectattr('repository_version', 'equalto', repo.pulp_href ~ 'versions/' ~ item.version | default ~ '/') }}"
31+
# If the distribution uses the latest version:
32+
latest_pub: "{{ pulp_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | sort(attribute='repository_version', reverse=True) }}"
33+
# If another distribution is being promoted to this one:
34+
promoted_dist: "{{ pulp_dists_list.distributions | selectattr('name', 'equalto', item.distribution | default) }}"
35+
promoted_pub: "{{ pulp_pubs_list.publications | selectattr('pulp_href', 'equalto', (promoted_dist | first).publication | default) }}"
36+
# Pick the right publication based on the type of distribution.
37+
pubs: "{{ specific_pub if item.version is defined else promoted_pub if item.distribution is defined else latest_pub }}"
38+
# Whether any distributions exist for this publication.
39+
pub_has_dists: >-
40+
{{ pulp_dists_list.distributions | selectattr('publication', 'equalto', pubs[0].pulp_href if item.state == 'present' else None) | list | length > 0 }}
41+
pulp.squeezer.deb_distribution:
42+
pulp_url: "{{ pulp_url }}"
43+
username: "{{ pulp_username }}"
44+
password: "{{ pulp_password }}"
45+
validate_certs: "{{ pulp_validate_certs | bool }}"
46+
name: "{{ item.name }}"
47+
base_path: "{{ item.base_path }}"
48+
publication: "{{ pubs[0].pulp_href if item.state == 'present' else omit }}"
49+
state: "{{ item.state }}"
50+
with_items: "{{ pulp_distribution_deb }}"
51+
when: >-
52+
item.state == 'absent' or
53+
not (item.skip_existing | default(pulp_distribution_deb_skip_existing) | bool and pub_has_dists)

roles/pulp_distribution/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
when: pulp_distribution_container | length > 0
66
tags: container
77

8+
- include_tasks: deb.yml
9+
tags: deb
10+
when: pulp_distribution_deb | length > 0
11+
812
- include_tasks: rpm.yml
913
tags: rpm
1014
when: pulp_distribution_rpm | length > 0

roles/pulp_publication/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Role variables
1010
* `pulp_username`: Username used to access Pulp server. Default is `admin`
1111
* `pulp_password`: Password used to access Pulp server. Default is unset
1212
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
13+
* `pulp_publication_deb`: List of publications of Deb repositories. Default is an empty list
1314
* `pulp_publication_rpm`: List of publications of RPM repositories. Default is an empty list
1415

1516
Example playbook
@@ -25,6 +26,14 @@ Example playbook
2526
- role: stackhpc.pulp.pulp_publication
2627
pulp_username: admin
2728
pulp_password: "{{ secrets_pulp_admin_password }}"
29+
pulp_publication_deb:
30+
# Create a publication of the latest version.
31+
- repository: ubuntu-focal
32+
state: present
33+
# Create a publication of version 2.
34+
- repository: ubuntu-focal
35+
version: 2
36+
state: present
2837
pulp_publication_rpm:
2938
# Create a publication of the latest version.
3039
- repository: centos-baseos

roles/pulp_publication/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ pulp_username: admin
44
pulp_password:
55
pulp_validate_certs: true
66

7+
pulp_publication_deb: []
78
pulp_publication_rpm: []
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Ensure Deb publications are defined
3+
pulp.squeezer.deb_publication:
4+
pulp_url: "{{ pulp_url }}"
5+
username: "{{ pulp_username }}"
6+
password: "{{ pulp_password }}"
7+
validate_certs: "{{ pulp_validate_certs | bool }}"
8+
repository: "{{ item.repository }}"
9+
state: "{{ item.state }}"
10+
version: "{{ item.version | default(omit) }}"
11+
with_items: "{{ pulp_publication_deb }}"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
- import_tasks: precheck.yml
33

4+
- include_tasks: deb.yml
5+
tags: deb
6+
when: pulp_publication_deb | length > 0
7+
48
- include_tasks: rpm.yml
59
tags: rpm
610
when: pulp_publication_rpm | length > 0

0 commit comments

Comments
 (0)