From b6bf9a8f0e30b8cfdcd727f1813ae72b747c3247 Mon Sep 17 00:00:00 2001 From: Sven Meeus Date: Sat, 29 Jul 2023 15:53:58 +0200 Subject: [PATCH] Allow organization to be specified --- roles/activation_keys/README.md | 1 + roles/activation_keys/tasks/main.yml | 2 +- roles/content_view_publish/tasks/main.yml | 2 +- roles/content_views/README.md | 4 ++++ roles/content_views/tasks/_create_content_view.yml | 4 ++-- roles/lifecycle_environments/README.md | 4 ++++ roles/lifecycle_environments/tasks/main.yml | 2 +- roles/repositories/README.md | 1 + roles/repositories/tasks/main.yml | 8 ++++---- roles/sync_plans/README.md | 2 +- roles/sync_plans/tasks/main.yml | 2 +- 11 files changed, 21 insertions(+), 11 deletions(-) diff --git a/roles/activation_keys/README.md b/roles/activation_keys/README.md index 4b04c5934..ac213ffc2 100644 --- a/roles/activation_keys/README.md +++ b/roles/activation_keys/README.md @@ -14,6 +14,7 @@ The main data structure for this role is the list of `foreman_activation_keys`. The following fields are required for an activation key but have defaults which make them optional for this role: +- `organization`: Organization to create the activation key for. Defaults to `foreman_organization` variable. - `lifecycle_environment`: Lifecycle Environment to assign to hosts registered with this activation key. Defaults to "Library". - `content_view`: Content View to assign to hosts registered with this activation key. Defaults to "Default Organization View". diff --git a/roles/activation_keys/tasks/main.yml b/roles/activation_keys/tasks/main.yml index 787c2ae88..ded6b97f4 100644 --- a/roles/activation_keys/tasks/main.yml +++ b/roles/activation_keys/tasks/main.yml @@ -5,7 +5,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.organization | default(foreman_organization) }}" name: "{{ item.name }}" description: "{{ item.description | default(omit) }}" lifecycle_environment: "{{ item.lifecycle_environment | default('Library') }}" diff --git a/roles/content_view_publish/tasks/main.yml b/roles/content_view_publish/tasks/main.yml index 5a8521b01..96ef1311c 100644 --- a/roles/content_view_publish/tasks/main.yml +++ b/roles/content_view_publish/tasks/main.yml @@ -5,7 +5,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ content_view.organization | default(foreman_organization) }}" content_view: "{{ content_view.name | default(content_view.content_view) | default(content_view) }}" description: "{{ content_view.description | default(omit) }}" version: "{{ content_view.description | default(omit) }}" diff --git a/roles/content_views/README.md b/roles/content_views/README.md index 67069882a..fc9182e94 100644 --- a/roles/content_views/README.md +++ b/roles/content_views/README.md @@ -12,6 +12,10 @@ The main data structure for this role is the list of `foreman_content_views`. Ea - `name` - the name of the content view +The following fields are required for a content view but have defaults which make them optional for this role: + +- `organization`: Organization to create thw cxontent view for. Defaults to `foreman_organization` variable. + Each content view also requires either a list of repositories or components (for a composite content view): - `repositories` - List of repositories to add to the content view. Each repository requires the following fields: - `name` - The name of the repository diff --git a/roles/content_views/tasks/_create_content_view.yml b/roles/content_views/tasks/_create_content_view.yml index 04257584f..e831746d7 100644 --- a/roles/content_views/tasks/_create_content_view.yml +++ b/roles/content_views/tasks/_create_content_view.yml @@ -5,7 +5,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ content_view.organization | default(foreman_organization) }}" name: "{{ content_view.name }}" auto_publish: "{{ content_view.auto_publish | default(omit) }}" components: "{{ content_view.components | default(omit) }}" @@ -21,7 +21,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ content_view.organization | default(foreman_organization) }}" name: "{{ item.name }}" content_view: "{{ content_view.name }}" repositories: "{{ item.repositories | default(omit) }}" diff --git a/roles/lifecycle_environments/README.md b/roles/lifecycle_environments/README.md index f3424927c..d0d7e01db 100644 --- a/roles/lifecycle_environments/README.md +++ b/roles/lifecycle_environments/README.md @@ -17,6 +17,10 @@ The main data structure for this role is the list of `foreman_lifecycle_environm the environments are listed in the order the path would exist. It can't be changed after the lifecycle environment has been created. +The following fields are required for a lifecycle environment but have defaults which make them optional for this role: + +- `organization`: Organization to create thw lifecycle environment for. Defaults to `foreman_organization` variable. + The following fields are optional and will be omitted by default: - `description`: Description of the lifecycle environment diff --git a/roles/lifecycle_environments/tasks/main.yml b/roles/lifecycle_environments/tasks/main.yml index f6f0ea1b2..df8626bba 100644 --- a/roles/lifecycle_environments/tasks/main.yml +++ b/roles/lifecycle_environments/tasks/main.yml @@ -5,7 +5,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.organization | default(foreman_organization) }}" name: "{{ item.name }}" description: "{{ item.description | default(omit) }}" prior: "{{ item.prior }}" diff --git a/roles/repositories/README.md b/roles/repositories/README.md index fe7028389..899bfe3f8 100644 --- a/roles/repositories/README.md +++ b/roles/repositories/README.md @@ -13,6 +13,7 @@ This role supports the [Common Role Variables](https://github.com/theforeman/for 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). + The `organization` field can be specified for a product and repositories. The `origanization` field defaults to `foreman_organization` variable for a product and defaults to the `organization` field of the product for repositories. A variety of examples are demonstrated in the data structure below: ```yaml diff --git a/roles/repositories/tasks/main.yml b/roles/repositories/tasks/main.yml index 1ca40fbef..2b2bc9937 100644 --- a/roles/repositories/tasks/main.yml +++ b/roles/repositories/tasks/main.yml @@ -5,7 +5,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.0.organization | default(foreman_organization) }}" product: "{{ item.0.name }}" name: "{{ item.1.name }}" all_repositories: false @@ -23,7 +23,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.0.organization | default(foreman_organization) }}" label: "{{ item.1 }}" all_repositories: true state: enabled @@ -37,7 +37,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.organization | default(foreman_organization) }}" name: "{{ item.name }}" label: "{{ item.label | default(omit) }}" gpg_key: "{{ item.gpg_key | default(omit) }}" @@ -51,7 +51,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.0.organization | default(foreman_organization) }}" name: "{{ item.1.name }}" url: "{{ item.1.url | default(omit) }}" product: "{{ item.0.name }}" diff --git a/roles/sync_plans/README.md b/roles/sync_plans/README.md index 179d85912..a6ed144cf 100644 --- a/roles/sync_plans/README.md +++ b/roles/sync_plans/README.md @@ -8,7 +8,7 @@ Role Variables This role supports the [Common Role Variables](https://github.com/theforeman/foreman-ansible-modules/blob/develop/README.md#common-role-variables). -- `foreman_sync_plans`: List of sync plans to create. Each sync plan is represented as a dictionary which specifies the `name` of the sync plan and the `products` assigned to the sync plan. It also specifies the `interval` which can be 'hourly', 'daily', 'weekly', or 'custom cron'. In case the 'custom cron' `interval` is used, it should also specify the `cron_expression`. Finally the sync plan should have a `sync_date` which specifies the first time that the sync plan will run. Optionally the sync plan can be enabled and disabled using the `enabled` parameter, and its state can be managed using `state`. +- `foreman_sync_plans`: List of sync plans to create. Each sync plan is represented as a dictionary which specifies the `name` of the sync plan and the `products` assigned to the sync plan. It also specifies the `interval` which can be 'hourly', 'daily', 'weekly', or 'custom cron'. In case the 'custom cron' `interval` is used, it should also specify the `cron_expression`. Finally the sync plan should have a `sync_date` which specifies the first time that the sync plan will run. Optionally the sync plan can be enabled and disabled using the `enabled` parameter, and its state can be managed using `state`. The `organization` field can be specified for a sync plan and defaults to `foreman_organization` variable. ```yaml foreman_sync_plans: diff --git a/roles/sync_plans/tasks/main.yml b/roles/sync_plans/tasks/main.yml index a98d613e8..47b389ef7 100644 --- a/roles/sync_plans/tasks/main.yml +++ b/roles/sync_plans/tasks/main.yml @@ -5,7 +5,7 @@ password: "{{ foreman_password | default(omit) }}" server_url: "{{ foreman_server_url | default(omit) }}" validate_certs: "{{ foreman_validate_certs | default(omit) }}" - organization: "{{ foreman_organization }}" + organization: "{{ item.organization | default(foreman_organization) }}" name: "{{ item.name }}" sync_date: "{{ item.sync_date }}" interval: "{{ item.interval }}"