-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add repo sync option #1127
base: develop
Are you sure you want to change the base?
Add repo sync option #1127
Changes from all commits
ab763e9
f7fd159
e26dff1
ab861df
c881d54
a198044
9e894e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- Add a role `repositories_sync` to sync products and repositories on-demand. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
theforeman.foreman.repositories_sync | ||
=============================== | ||
|
||
This role syncs Products and Repositories. This role uses the same data structure as `theforeman.foreman.repositories`. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
This role supports the [Common Role Variables](https://github.com/theforeman/foreman-ansible-modules/blob/develop/README.md#common-role-variables). | ||
|
||
- `products`: List of products to manage. | ||
Each product is represented as a dictionary and can include `repository_sets` which represent Red Hat Repositories and should be used when the product name matches an existing Red Hat Product. | ||
Each element of `repository_sets` must have a `name` and should specify the `basearch` and/or `releasever` only when multiple versions are available for that Product. | ||
All repository sets for a Red Hat Product can be enabled by omitting `repository_sets` and instead specifying that the Product has `all_repositories: True`. When using this option it is also necessary to specify a list of repository `label`s for the Product (e.g. rhel-7-server-rpms). Be wary that this option can result in enabling a large number of unused repositories that, if added to sync plans, can greatly increase sync times and rapidly fill disk space. | ||
Custom (i.e. non Red Hat) Products can also be defined, with associated `repositories` which represent custom repositories, and are required to have a `name`, `url`, and `content_type`; they may require additional fields and can take any parameter supported by [theforeman.foreman.repository](https://theforeman.github.io/foreman-ansible-modules/develop/plugins/repository_module.html). Repositories will not be synced automatically when enabled. Specify the `sync` option on the product to run an initial sync of all repositories in the product. | ||
A variety of examples are demonstrated in the data structure below: | ||
|
||
```yaml | ||
products: | ||
- name: Red Hat Enterprise Linux Server | ||
repository_sets: | ||
- name: Red Hat Enterprise Linux 7 Server (RPMs) | ||
basearch: x86_64 | ||
releasever: 7Server | ||
- name: Red Hat Enterprise Linux 6 Server (RPMs) | ||
basearch: x86_64 | ||
releasever: 6Server | ||
- name: Red Hat Enterprise Linux 7 Server - Extras (RPMs) | ||
basearch: x86_64 | ||
- name: Red Hat Enterprise Linux 7 Server - Optional (RPMs) | ||
basearch: x86_64 | ||
- name: Red Hat Software Collections (for RHEL Server) | ||
repository_sets: | ||
- name: Red Hat Software Collections RPMs for Red Hat Enterprise Linux 7 Server | ||
basearch: x86_64 | ||
releasever: 7Server | ||
- name: Red Hat Software Collections RPMs for Red Hat Enterprise Linux 6 Server | ||
basearch: x86_64 | ||
releasever: 6Server | ||
- name: Red Hat Enterprise Linux for x86_64 | ||
repository_sets: | ||
- name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) | ||
releasever: 8 | ||
- name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) | ||
releasever: 8 | ||
- name: Red Hat Software Collections (for RHEL Server) | ||
all_repositories: True | ||
labels: | ||
- rhel-server-rhscl-7-rpms | ||
- name: CentOS 8 | ||
repositories: | ||
- name: BaseOS x86_64 | ||
content_type: yum | ||
url: http://mirror.centos.org/centos/8/BaseOS/x86_64/os/ | ||
- name: AppStream x86_64 | ||
content_type: yum | ||
url: http://mirror.centos.org/centos/8/AppStream/x86_64/os/ | ||
- name: Debian 10 | ||
repositories: | ||
- name: Debian 10 main | ||
content_type: deb | ||
url: http://deb.debian.org/debian | ||
deb_components: main | ||
deb_architectures: amd64 | ||
deb_releases: buster | ||
- name: Foreman Client | ||
repositories: | ||
- name: Foreman Client Debian 10 | ||
url: https://apt.atix.de/debian | ||
content_type: deb | ||
deb_components: main | ||
deb_architectures: amd64 | ||
deb_releases: stable | ||
- name: Foreman Client CentOS 7 | ||
url: https://yum.theforeman.org/client/latest | ||
content_type: yum | ||
``` | ||
|
||
Example Playbooks | ||
----------------- | ||
|
||
This example enables several Red Hat Repositories. There are a few important points to note about the structure of the data in the example: | ||
- RHEL 8 repos have a different product name than previous RHEL versions. | ||
- The RHEL 8 product already contains the `basearch` so it should not be specified on the RHEL 8 `repository_sets`, and the naming convention for `releasever` changed with RHEL 8 since system purpose removes the need for separate distributions like `Server` and `Workstation`. | ||
- The optional and extras repositories do not have point releases so `releasever` should be omitted. | ||
- RHEL 8 repos will be synced after being enabled. Without the `sync` parameter, the RHEL 6 and 7 repositories will only be enabled. | ||
|
||
```yaml | ||
- hosts: localhost | ||
roles: | ||
- role: theforeman.foreman.repositories | ||
vars: | ||
server_url: https://foreman.example.com | ||
username: "admin" | ||
password: "changeme" | ||
organization: "Default Organization" | ||
products: | ||
- name: Red Hat Enterprise Linux Server | ||
repository_sets: | ||
- name: Red Hat Enterprise Linux 7 Server (RPMs) | ||
basearch: x86_64 | ||
releasever: 7Server | ||
- name: Red Hat Enterprise Linux 6 Server (RPMs) | ||
basearch: x86_64 | ||
releasever: 6Server | ||
- name: Red Hat Enterprise Linux 7 Server - Extras (RPMs) | ||
basearch: x86_64 | ||
- name: Red Hat Enterprise Linux 7 Server - Optional (RPMs) | ||
basearch: x86_64 | ||
- name: Red Hat Enterprise Linux for x86_64 | ||
sync: true | ||
repository_sets: | ||
- name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) | ||
releasever: 8 | ||
- name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) | ||
releasever: 8 | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
products: [] |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||||||||||
--- | ||||||||||||||||||
- name: sync product | ||||||||||||||||||
theforeman.foreman.repository_sync: | ||||||||||||||||||
username: "{{ username | default(omit) }}" | ||||||||||||||||||
password: "{{ password | default(omit) }}" | ||||||||||||||||||
server_url: "{{ server_url | default(omit) }}" | ||||||||||||||||||
validate_certs: "{{ validate_certs | default(omit) }}" | ||||||||||||||||||
organization: "{{ organization }}" | ||||||||||||||||||
product: "{{ item.0.name }}" | ||||||||||||||||||
with_subelements: | ||||||||||||||||||
- "{{ products | selectattr('repository_sets', 'defined') | list }}" | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this means it won't sync any custom repositories that the |
||||||||||||||||||
- repository_sets | ||||||||||||||||||
when: item.0.sync | default(false) | bool | ||||||||||||||||||
Comment on lines
+9
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There is no need to iterate over the repositories anymore, as we're syncing by-product now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks unrelated and unneeded?