diff --git a/roles/mtv_management/tasks/_mtv_storage_map.yml b/roles/mtv_management/tasks/_mtv_storage_map.yml index ab05c6c..ade482b 100644 --- a/roles/mtv_management/tasks/_mtv_storage_map.yml +++ b/roles/mtv_management/tasks/_mtv_storage_map.yml @@ -2,7 +2,7 @@ - name: _mtv_storage_map | Initialize data structures ansible.builtin.set_fact: - mtv_management_mtv_storagemaps: {} + mtv_management_mtv_storagemap_maps: {} - name: _mtv_storage_map | Verify Storage Map Overrides do not contain both includes and excludes ansible.builtin.fail: @@ -41,9 +41,46 @@ mtv_management_inventory_query_result_var: mtv_destination_datastores when: "'vsphere' in provider" +- name: _mtv_storage_map | Extract included datastore IDs from overrides + ansible.builtin.set_fact: + mtv_management_mtv_allowed_datastore_ids: >- + {{ + mtv_management_storage_map_overrides + | selectattr('include', 'defined') + | selectattr('include', 'equalto', true) + | map(attribute='id') + | list + }} + when: + - mtv_management_storage_map_overrides is defined + - mtv_management_storage_map_overrides | length > 0 + - mtv_management_storage_map_overrides | selectattr('include', 'defined') | list | length > 0 + +- name: _mtv_storage_map | Extract excluded datastore IDs from overrides + ansible.builtin.set_fact: + mtv_management_mtv_excluded_datastore_ids: >- + {{ + mtv_management_storage_map_overrides + | selectattr('exclude', 'defined') + | selectattr('exclude', 'equalto', true) + | map(attribute='id') + | list + }} + when: + - mtv_management_storage_map_overrides is defined + - mtv_management_storage_map_overrides | length > 0 + - mtv_management_storage_map_overrides | selectattr('exclude', 'defined') | list | length > 0 + - name: _mtv_storage_map | Process VMware Datastores ansible.builtin.include_tasks: _mtv_storage_map_process_datastore.yml - loop: "{{ mtv_destination_datastores }}" + loop: >- + {{ + (mtv_destination_datastores | selectattr('id', 'in', mtv_management_mtv_allowed_datastore_ids) | list) + if (mtv_management_mtv_allowed_datastore_ids | default([]) | length > 0) + else (mtv_destination_datastores | rejectattr('id', 'in', mtv_management_mtv_excluded_datastore_ids | default([])) | list) + if (mtv_management_mtv_excluded_datastore_ids | default([]) | length > 0) + else mtv_destination_datastores + }} loop_control: loop_var: mtv_vmware_datastore when: @@ -53,7 +90,14 @@ - name: _mtv_storage_map | Process Ovirt Datastores ansible.builtin.include_tasks: _mtv_storage_map_process_datastore.yml - loop: "{{ mtv_destination_datastores }}" + loop: >- + {{ + (mtv_destination_datastores | selectattr('id', 'in', mtv_management_mtv_allowed_datastore_ids) | list) + if (mtv_management_mtv_allowed_datastore_ids | default([]) | length > 0) + else (mtv_destination_datastores | rejectattr('id', 'in', mtv_management_mtv_excluded_datastore_ids | default([])) | list) + if (mtv_management_mtv_excluded_datastore_ids | default([]) | length > 0) + else mtv_destination_datastores + }} loop_control: loop_var: mtv_ovirt_datastore when: diff --git a/roles/mtv_management/tasks/_mtv_storage_map_process_datastore.yml b/roles/mtv_management/tasks/_mtv_storage_map_process_datastore.yml index 453da6d..a74f877 100644 --- a/roles/mtv_management/tasks/_mtv_storage_map_process_datastore.yml +++ b/roles/mtv_management/tasks/_mtv_storage_map_process_datastore.yml @@ -54,15 +54,13 @@ - name: _mtv_storage_map_process_datastore | Add VMware StorageMap Map to Dict ansible.builtin.set_fact: - mtv_management_mtv_storagemap_maps: "{{ mtv_management_mtv_storagemap_maps | default({}) | ansible.builtin.combine({mtv_vmware_datastore.selfLink: mtv_management_storage_map_map}, recursive=true) }}" # noqa: yaml[line-length] + mtv_management_mtv_storagemap_maps: "{{ mtv_management_mtv_storagemap_maps | default({}) | ansible.builtin.combine({(mtv_vmware_datastore.selfLink + '-' + _mtv_management_storage_map_storage_class): mtv_management_storage_map_map}, recursive=true) }}" # noqa: yaml[line-length] when: - mtv_vmware_datastore is defined - - "(('include' in mtv_management_mtv_vmware_datastore_overrides and mtv_management_storage_map_overrides | selectattr('include', 'defined') | list | length > 0) or (mtv_management_storage_map_overrides | selectattr('include', 'defined') | list | length == 0 and mtv_management_storage_map_overrides | selectattr('exclude', 'defined') | list | length == 0)) or ('exclude' not in mtv_management_mtv_vmware_datastore_overrides and mtv_management_storage_map_overrides | selectattr('exclude', 'defined') | list | length > 0)" # noqa: yaml[line-length] - name: _mtv_storage_map_process_datastore | Add Ovirt StorageMap Map to Dict ansible.builtin.set_fact: - mtv_management_mtv_storagemap_maps: "{{ mtv_management_mtv_storagemap_maps | default({}) | ansible.builtin.combine({mtv_ovirt_datastore.selfLink: mtv_management_storage_map_map}, recursive=true) }}" # noqa: yaml[line-length] + mtv_management_mtv_storagemap_maps: "{{ mtv_management_mtv_storagemap_maps | default({}) | ansible.builtin.combine({(mtv_ovirt_datastore.selfLink + '-' + _mtv_management_storage_map_storage_class): mtv_management_storage_map_map}, recursive=true) }}" # noqa: yaml[line-length] when: - mtv_ovirt_datastore is defined - - "(('include' in mtv_management_mtv_ovirt_datastore_overrides and mtv_management_storage_map_overrides | selectattr('include', 'defined') | list | length > 0) or (mtv_management_storage_map_overrides | selectattr('include', 'defined') | list | length == 0 and mtv_management_storage_map_overrides | selectattr('exclude', 'defined') | list | length == 0)) or ('exclude' not in mtv_management_mtv_ovirt_datastore_overrides and mtv_management_storage_map_overrides | selectattr('exclude', 'defined') | list | length > 0)" # noqa: yaml[line-length] ...