-
Notifications
You must be signed in to change notification settings - Fork 0
/
pulp_mirror_rpm_repository.yml
201 lines (184 loc) · 8.03 KB
/
pulp_mirror_rpm_repository.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
---
# Playbook to manage and synchronise Red Hat repository (mirrors) on Pulp
#
# Author: Stefan Joosten <stefan•ɑƬ•atcomputing•ɖɵʈ•nl>
# License: GPLv3
#
- name: Perform management of Red Hat repositories on a Pulp repository server
hosts: pulp
force_handlers: true
module_defaults:
pulp.squeezer.status: &pulp_connection_details # & creates YAML anchor
pulp_url: "{{ pulp_url }}" # from group_vars/pulp; e.g.: http://{{ inventory_hostname }}:8080
username: "{{ pulp_username }}" # from group_vars/pulp
password: "{{ pulp_password }}" # from group_vars/pulp
validate_certs: false
pulp.squeezer.rpm_distribution:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.rpm_publication:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.rpm_repository:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.rpm_remote:
<<: *pulp_connection_details # alias to content of pulp_connection_details
pulp.squeezer.rpm_sync:
<<: *pulp_connection_details # alias to content of pulp_connection_details
vars:
redhat_uep_ca_path: /etc/rhsm/ca/redhat-uep.pem
redhat_repositories:
# - name: rhel-8-for-x86_64-baseos-rpms
# description: Mirror of Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
# state: present
# remote:
# name: rhel-8-for-x86_64-baseos-rpms
# state: present
# url: https://cdn.redhat.com/content/dist/rhel8/8/x86_64/baseos/os
# #proxy_url: http://my.internal.proxy:3128
# requires_subscription: true
- name: my_rpmfusion_steam_repo
description: Mirror of RPMFusion Non-Free Steam repository
state: present
remote:
# name: local_rpmfusion-nonfree-steam
# state: present
# url: http://{{ ansible_facts.fqdn }}:8000/rpmfusion-nonfree-steam/
name: remote_rpmfusion-nonfree-steam
state: present
url: http://ftp.nluug.nl/os/Linux/distr/rpmfusion/nonfree/fedora/steam/38/x86_64/
tasks:
- name: Refresh and read status from Pulp API # noqa: args[module]
pulp.squeezer.status:
refresh_api_cache: true
- name: Check for repositories requiring subscription # trapdoor: one set? => get subscription
ansible.builtin.set_fact:
get_subscription: true
loop: "{{ redhat_repositories }}"
loop_control:
loop_var: repository
when:
- repository.remote.requires_subscription is defined
- repository.remote.requires_subscription
# Major assumption/requirement: Pulp is running on a subscribed Red Hat box (i.e. has access)
# Idea for improvement: check if that is the case?
- name: Acquire Red Hat Subscription for the repositories that require authentication
when:
- get_subscription is defined
- get_subscription
block:
- name: Find Red Hat Subscription client certificate file
ansible.builtin.find:
paths: /etc/pki/entitlement/
use_regex: true
patterns: '^[0-9]*\.pem'
register: rh_client_cert
- name: Find Red Hat Subscription client key file
ansible.builtin.find:
paths: /etc/pki/entitlement/
use_regex: true
patterns: '^[0-9]*-key\.pem'
register: rh_client_key
- name: Verify Red Hat UEP CA certificate file exists
ansible.builtin.stat:
path: "{{ redhat_uep_ca_path }}"
register: rh_uep_ca
- name: Test the found subscription files
ansible.builtin.assert:
that:
- rh_client_cert.files | length == 1
- rh_client_cert.files[0].isreg
- rh_client_cert.files[0].size > 1000
- rh_client_key.files | length == 1
- rh_client_key.files[0].isreg
- rh_client_key.files[0].size > 1000
- rh_uep_ca.stat.exists
- rh_uep_ca.stat.isreg
- rh_uep_ca.stat.size > 1000
quiet: true
- name: Grab the Red Hat Subscription client certificate file
ansible.builtin.slurp:
src: "{{ rh_client_cert.files[0].path }}"
register: rh_client_cert_file
- name: Grab the Red Hat Subscription client key file
ansible.builtin.slurp:
src: "{{ rh_client_key.files[0].path }}"
register: rh_client_key_file
- name: Grab the Red Hat UEP CA certificate file
ansible.builtin.slurp:
src: "{{ redhat_uep_ca_path }}"
register: rh_uep_ca_file
# End of block "Acquire Red Hat Subscription for the repositories that require authentication"
- name: Ensure RPM repository # noqa: args[module]
pulp.squeezer.rpm_repository:
name: "{{ repository.name }}"
description: "{{ repository.description }}"
state: "{{ repository.state | default('present') }}"
loop: "{{ redhat_repositories }}"
loop_control:
label: "{{ repository.name }}"
loop_var: repository
- name: Create RPM remote (without subscription) # noqa: args[module]
pulp.squeezer.rpm_remote:
name: "{{ repository.remote.name }}"
url: "{{ repository.remote.url }}"
proxy_url: "{{ repository.remote.proxy_url | default(omit) }}"
state: "{{ repository.remote.state | default('present') }}"
policy: immediate
loop: "{{ redhat_repositories }}"
loop_control:
label: "{{ repository.remote.name }}"
loop_var: repository
when:
- repository.remote is defined
- repository.remote.requires_subscription is not defined
- not repository.remote.requires_subscription | default(false)
- name: Create RPM remote (with subscription) # noqa: args[module]
pulp.squeezer.rpm_remote:
name: "{{ repository.remote.name }}"
url: "{{ repository.remote.url }}"
proxy_url: "{{ repository.remote.proxy_url | default(omit) }}"
state: "{{ repository.remote.state | default('present') }}"
ca_cert: "{{ rh_uep_ca_file.content | b64decode }}"
client_cert: "{{ rh_client_cert_file.content | b64decode }}"
client_key: "{{ rh_client_key_file.content | b64decode }}"
policy: immediate
loop: "{{ redhat_repositories }}"
loop_control:
label: "{{ repository.remote.name }}"
loop_var: repository
when:
- repository.remote is defined
- repository.remote.requires_subscription is defined
- repository.remote.requires_subscription | bool
- name: Synchronize repository # noqa: args[module]
pulp.squeezer.rpm_sync:
repository: "{{ repository.name }}"
remote: "{{ repository.remote.name }}"
sync_policy: "{{ repository.sync_policy | default('mirror_complete') }}"
register: sync_task
loop: "{{ redhat_repositories }}"
loop_control:
label: "Sync remote {{ repository.remote.name | default('unknown') }} into repository {{ repository.name }}"
loop_var: repository
ignore_errors: true # when sync fails for one item, continue with the others regardless
when:
- repository.remote is defined
- repository.remote.state is not defined or repository.remote.state == 'present'
- repository.state is not defined or repository.state == 'present'
- name: Report synchronised repository status
ansible.builtin.debug:
var: sync
verbosity: 1
loop: "{{ sync_task.results }}"
loop_control:
label: "{{ sync.repository.name }}"
loop_var: sync
- name: Make the rpm distribution track the latest repository version
pulp.squeezer.rpm_distribution:
name: "{{ repository.name }}"
base_path: "{{ repository.name }}"
repository: "{{ repository.name }}"
state: present
loop: "{{ redhat_repositories }}"
loop_control:
label: "{{ repository.name }}"
loop_var: repository