Skip to content

Commit a6035d1

Browse files
authored
Merge pull request #17 from stackhpc/pulp-distribution-rpm
Pulp publication & distribution for RPM content
2 parents 251e48d + b374bd6 commit a6035d1

File tree

10 files changed

+196
-0
lines changed

10 files changed

+196
-0
lines changed

roles/pulp_distribution/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
pulp_distribution
2+
=================
3+
4+
This role configures Pulp server distributions.
5+
6+
Role variables
7+
--------------
8+
9+
* `pulp_url`: URL of Pulp server. Default is `http://localhost:8080`
10+
* `pulp_username`: Username used to access Pulp server. Default is `admin`
11+
* `pulp_password`: Password used to access Pulp server. Default is unse
12+
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
13+
* `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`.
18+
19+
Example playbook
20+
----------------
21+
22+
```
23+
---
24+
- name: Manage Pulp distributions
25+
any_errors_fatal: True
26+
gather_facts: True
27+
hosts: all
28+
roles:
29+
- role: stackhpc.pulp.pulp_distribution
30+
pulp_url: "https://pulp.example.com"
31+
pulp_username: admin
32+
pulp_password: "{{ secrets_pulp_admin_password }}"
33+
pulp_distribution_rpm:
34+
# Distribute the latest version of the centos-baseos repository.
35+
- name: centos-baseos
36+
base_path: centos-baseos
37+
repository: centos-baseos
38+
state: present
39+
# Distribute version 2 of the centos-appstream repository.
40+
- name: centos-appstream
41+
base_path: centos-appstream
42+
repository: centos-appstream
43+
version: 2
44+
state: present
45+
# Distribute the same publication as the centos-baseos distribution.
46+
- name: centos-baseos-production
47+
base_path: centos-baseos-production
48+
distribution: centos-baseos
49+
state: present
50+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
pulp_url: http://localhost:8080
3+
pulp_username: admin
4+
pulp_password:
5+
pulp_validate_certs: true
6+
7+
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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- import_tasks: precheck.yml
3+
4+
- include_tasks: rpm.yml
5+
tags: rpm
6+
when: pulp_distribution_rpm | length > 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Check Pulp server status
3+
pulp.squeezer.status:
4+
pulp_url: "{{ pulp_url }}"
5+
username: "{{ pulp_username }}"
6+
password: "{{ pulp_password }}"
7+
validate_certs: "{{ pulp_validate_certs | bool }}"
8+
refresh_api_cache: true
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
- name: Query repositories
3+
pulp.squeezer.rpm_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.rpm_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.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+
26+
- name: Ensure RPM 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 pubication based on the type of distribution.
37+
pub: "{{ specific_pub | first if item.version is defined else promoted_pub | first if item.distribution is defined else latest_pub | first }}"
38+
# Whether any distributions exist for this publication.
39+
pub_has_dists: "{{ pulp_dists_list.distributions | selectattr('publication', 'equalto', pub.pulp_href) | list | length > 0 }}"
40+
pulp.squeezer.rpm_distribution:
41+
pulp_url: "{{ pulp_url }}"
42+
username: "{{ pulp_username }}"
43+
password: "{{ pulp_password }}"
44+
validate_certs: "{{ pulp_validate_certs | bool }}"
45+
name: "{{ item.name }}"
46+
base_path: "{{ item.base_path }}"
47+
publication: "{{ pub.pulp_href if item.state == 'present' else omit }}"
48+
state: "{{ item.state }}"
49+
with_items: "{{ pulp_distribution_rpm }}"
50+
when: >-
51+
item.state == 'absent' or
52+
not (item.skip_existing | default(pulp_distribution_rpm_skip_existing) | bool and pub_has_dists)

roles/pulp_publication/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
pulp_publication
2+
================
3+
4+
This role configures Pulp server publications.
5+
6+
Role variables
7+
--------------
8+
9+
* `pulp_url`: URL of Pulp server. Default is `http://localhost:8080`
10+
* `pulp_username`: Username used to access Pulp server. Default is `admin`
11+
* `pulp_password`: Password used to access Pulp server. Default is unset
12+
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
13+
* `pulp_publication_rpm`: List of publications of RPM repositories. Default is an empty list
14+
15+
Example playbook
16+
----------------
17+
18+
```
19+
---
20+
- name: Manage Pulp publications
21+
any_errors_fatal: True
22+
gather_facts: True
23+
hosts: all
24+
roles:
25+
- role: stackhpc.pulp.pulp_publication
26+
pulp_username: admin
27+
pulp_password: "{{ secrets_pulp_admin_password }}"
28+
pulp_publication_rpm:
29+
# Create a publication of the latest version.
30+
- repository: centos-baseos
31+
state: present
32+
# Create a publication of version 2.
33+
- repository: centos-appstream
34+
version: 2
35+
state: present
36+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
pulp_url: http://localhost:8080
3+
pulp_username: admin
4+
pulp_password:
5+
pulp_validate_certs: true
6+
7+
pulp_publication_rpm: []
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- import_tasks: precheck.yml
3+
4+
- include_tasks: rpm.yml
5+
tags: rpm
6+
when: pulp_publication_rpm | length > 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Check Pulp server status
3+
pulp.squeezer.status:
4+
pulp_url: "{{ pulp_url }}"
5+
username: "{{ pulp_username }}"
6+
password: "{{ pulp_password }}"
7+
validate_certs: "{{ pulp_validate_certs | bool }}"
8+
refresh_api_cache: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Ensure RPM publications are defined
3+
pulp.squeezer.rpm_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_rpm }}"

0 commit comments

Comments
 (0)