diff --git a/roles/mtv_management/defaults/main.yml b/roles/mtv_management/defaults/main.yml index ef65223..ef1a074 100644 --- a/roles/mtv_management/defaults/main.yml +++ b/roles/mtv_management/defaults/main.yml @@ -136,10 +136,10 @@ mtv_management_vmware_vddk_init_image_credentials_secret: "" # description: Service Account to Associate the VDDK Init Image Pull Secret mtv_management_vmware_vddk_init_image_service_account: default -# Overrides # title: MTV Storage Map Override # required: False -# description: Overrides for the storage map +# description: Overrides for the default storage map. Note: This variable is ignored if +# mtv_management_multiple_storage_maps_overrides is populated. mtv_management_storage_map_overrides: [ # - id: # storageClass: @@ -147,6 +147,23 @@ mtv_management_storage_map_overrides: [ # include: true ] +# title: MTV Multiple Storage Maps Overrides +# required: False +# description: Dictionary of multiple storage maps. Takes precedence over +# mtv_management_storage_map_overrides. Map keys are sanitized to comply +# with Kubernetes RFC 1123 naming conventions (e.g., lowercase, hyphens only) +mtv_management_multiple_storage_maps_overrides: {} +# map_name1: +# - id: +# storageClass: +# exclude: true +# include: true +# map_name2: +# - id: +# storageClass: +# exclude: true +# include: true + # title: MTV Network Map Overrides # required: False # description: Overrides for the network map diff --git a/roles/mtv_management/tasks/mtv_maps.yml b/roles/mtv_management/tasks/mtv_maps.yml index b27c102..7b4298a 100644 --- a/roles/mtv_management/tasks/mtv_maps.yml +++ b/roles/mtv_management/tasks/mtv_maps.yml @@ -11,9 +11,15 @@ that: - mtv_providers is defined - mtv_providers.vsphere is defined - - mtv_providers.vsphere | selectattr('name', 'equalto', mtv_management_source_target) | selectattr('namespace', 'equalto', mtv_management_provider_namespace) | list | length == 1 # noqa: yaml[line-length] + - >- + mtv_providers.vsphere + | selectattr('name', 'equalto', mtv_management_source_target) + | selectattr('namespace', 'equalto', mtv_management_provider_namespace) + | list | length == 1 quiet: true - fail_msg: "Source Provider with name '{{ mtv_management_source_target }}' not found in namespace '{{ mtv_management_provider_namespace }}'" # noqa: yaml[line-length] + fail_msg: >- + Source Provider with name '{{ mtv_management_source_target }}' + not found in namespace '{{ mtv_management_provider_namespace }}' when: "'vsphere' in provider" - name: mtv_maps | Verify Ovirt Source Provider Exists @@ -25,7 +31,6 @@ quiet: true fail_msg: "Source Provider with name '{{ mtv_management_source_target }}' not found in namespace '{{ mtv_management_provider_namespace }}'" # noqa: yaml[line-length] when: "'ovirt' in provider" - - name: mtv_maps | Destination OpenShift Destination Provider Exists ansible.builtin.assert: that: @@ -35,10 +40,37 @@ quiet: true fail_msg: "Destination Provider with name '{{ mtv_management_destination_target }}' not found in namespace '{{ mtv_management_provider_namespace }}'" # noqa: yaml[line-length] -- name: mtv_maps | Configure MTV Storage Maps - ansible.builtin.include_tasks: _mtv_storage_map.yml +- name: mtv_maps | Verify mutually exclusive storage map overrides + ansible.builtin.assert: + that: + - >- + not (mtv_management_multiple_storage_maps_overrides | default({}) | length > 0 + and mtv_management_storage_map_overrides | default([]) | length > 0) + quiet: true + fail_msg: >- + Cannot define both mtv_management_storage_map_overrides and + mtv_management_multiple_storage_maps_overrides simultaneously. + Please choose one. when: mtv_management_map_storage is defined and mtv_management_map_storage | bool +- name: mtv_maps | Configure MTV Storage Maps (Multiple) + ansible.builtin.include_tasks: _mtv_storage_map.yml + loop: "{{ mtv_management_multiple_storage_maps_overrides | dict2items }}" + vars: + defined_storage_map_name: "{{ item.key }}" + mtv_management_storage_map_overrides: "{{ item.value }}" + when: + - mtv_management_map_storage is defined and mtv_management_map_storage | bool + - mtv_management_multiple_storage_maps_overrides is defined + - mtv_management_multiple_storage_maps_overrides | length > 0 + +- name: mtv_maps | Configure MTV Storage Maps + ansible.builtin.include_tasks: _mtv_storage_map.yml + when: + - mtv_management_map_storage is defined and mtv_management_map_storage | bool + - >- + mtv_management_multiple_storage_maps_overrides is not defined or + mtv_management_multiple_storage_maps_overrides | length == 0 - name: mtv_maps | Configure MTV Network Map ansible.builtin.include_tasks: _mtv_network_map.yml when: mtv_management_map_networks is defined and mtv_management_map_networks | bool diff --git a/roles/mtv_management/templates/storagemap.yml.j2 b/roles/mtv_management/templates/storagemap.yml.j2 index 7c95846..7686f43 100644 --- a/roles/mtv_management/templates/storagemap.yml.j2 +++ b/roles/mtv_management/templates/storagemap.yml.j2 @@ -1,7 +1,7 @@ apiVersion: forklift.konveyor.io/v1beta1 kind: StorageMap metadata: - name: "{{ (mtv_management_source_target + '-' + mtv_management_destination_target) | infra.openshift_virtualization_migration.rfc1123 }}" + name: "{{ defined_storage_map_name | default(mtv_management_source_target + '-' + mtv_management_destination_target) | infra.openshift_virtualization_migration.rfc1123 }}" namespace: "{{ mtv_management_migration_namespace }}" spec: provider: