diff --git a/README.md b/README.md index 4c468e7..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,154 +0,0 @@ -# Ansible for OpenShift Virtualization Migration - -![GitHub Release](https://img.shields.io/github/v/release/redhat-cop/openshift_virtualization_migration?include_prereleases&style=flat-square) -[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/redhat-cop/openshift_virtualization_migration/ci.yml?style=flat-square&label=release)](https://github.com/redhat-cop/openshift_virtualization_migration/actions) -[![Semantic Versioning](https://img.shields.io/badge/semver-2.0.0-blue?style=flat-square)](https://semver.org/) -[![License](https://img.shields.io/github/license/redhat-cop/openshift_virtualization_migration?style=flat-square)](LICENSE) - - - -- [Ansible for OpenShift Virtualization Migration](#ansible-for-openshift-virtualization-migration) - - [Description](#description) - - [Documentation](#documentation) - - [Release Notes](#release-notes) - - [Roles](#roles) - - [Requirements](#requirements) - - [Installation](#installation) - - [Use Cases](#use-cases) - - [Testing](#testing) - - [Support](#support) - - [License](#license) - - - -## Description - -This collection enables the migration journey of Virtual Machine (VM) workloads from existing hypervisors to Red Hat OpenShift Virtualization using Ansible Automation Platform. Additionally it provides content for the management and maintenance of VM workloads within Red Hat OpenShift Virtualization. - -## Documentation - -* [Contributing Guide](CONTRIBUTING.md) -* [Disconnected Environment Setup](docs/disconnected_environment_guide.md) -* [Secure Credential Management](docs/secure_credential_management.md) -* [Secure Credential Practices](docs/secure_credential_practices.md) - -## Release Notes - -See [CHANGELOG.md](CHANGELOG.md) for release history and changes. - -## Roles - -This collection includes the following roles for managing OpenShift Virtualization migrations: - - -* [aap_deploy](roles/aap_deploy/README.md) - Deploys an instance of Ansible Automation Platform. -* [aap_machine_credentials](roles/aap_machine_credentials/README.md) - Management of Machine Credentials. -* [aap_seed](roles/aap_seed/README.md) - Populates an Ansible Automation Platform instance. -* [bootstrap](roles/bootstrap/README.md) - Initialization of the Ansible for OpenShift Virtualization Migration environment. -* [create_mf_aap_token](roles/create_mf_aap_token/README.md) - create_mf_aap_token -* [mtv_management](roles/mtv_management/README.md) - Management of the Migration Toolkit for Virtualization (MTV). -* [mtv_migrate](roles/mtv_migrate/README.md) - Migration of Virtual Machines from Source to Destination. -* [network_mgmt](roles/network_mgmt/README.md) - Management of network related components. -* [operator_management](roles/operator_management/README.md) - Management of OpenShift Operators. -* [validate_migration](roles/validate_migration/README.md) - Verification of an Ansible for OpenShift Virtualization Migration environment. -* [vm_backup_restore](roles/vm_backup_restore/README.md) - Virtual Machine backup and restore capabilities. -* [vm_collect](roles/vm_collect/README.md) - Collection of Migration Toolkit for Virtualization inventory information. -* [vm_hot_plug](roles/vm_hot_plug/README.md) - Hot Plug Virtual Machine resources. -* [vm_lifecycle](roles/vm_lifecycle/README.md) - Management of the lifecycle activities of Virtual Machines. -* [vm_mac_address](roles/vm_mac_address/README.md) - Management of Virtual Machine MAC Addresses. -* [vm_networking](roles/vm_networking/README.md) - Management of Virtual Machine networking. -* [vm_patching](roles/vm_patching/README.md) - Patching related activities for Virtual Machines. -* [vm_ssh](roles/vm_ssh/README.md) - Management of SSH keys for Virtual Machines in OpenShift. - - -## Requirements - -The following Ansible Collections are required: - -```yaml ---- -collections: - - name: redhat.openshift_virtualization - - name: redhat.openshift - - name: vmware.vmware_rest - - name: ansible.posix - - name: infra.aap_utilities - - name: kubernetes.core - - name: community.crypto - - name: community.general - - name: community.vmware - - # AAP <=2.4 - - name: infra.controller_configuration - - name: ansible.controller - version: "<=4.5.12" - - # AAP 2.5+ - - name: ansible.platform - - name: ansible.controller - - name: infra.aap_configuration -... -``` - -## Installation - -You can install the `infra.openshift_virtualization_migration` collection with the Ansible Galaxy CLI: - -```shell -ansible-galaxy collection install infra.openshift_virtualization_migration -``` - -Note that if you install any collections from Ansible Galaxy, they will not be upgraded automatically when you upgrade the Ansible package. - -To upgrade the collection to the latest available version, run the following command: - -``` -ansible-galaxy collection install infra.openshift_virtualization_migration --upgrade -``` - -You can also include it in a `requirements.yml` file and install it with `ansible-galaxy collection install -r requirements.yml`, using the format: - -```yaml ---- -collections: - - name: infra.openshift_virtualization_migration - # If you need a specific version of the collection, you can specify like this: - # version: ... -``` - -See [using Ansible collections](https://docs.ansible.com/ansible/devel/user_guide/collections_using.html) for more details. - -## Use Cases - -This collection is ideal for accomplishing the following using Ansible automation: - -* Analyzing existing Virtual Machine hypervisor environments. -* Installing and configuring Ansible Automation Platform. -* Preparing OpenShift environments to support Virtual Machines and migrating Virtual Machines from existing hypervisors using the Migration Toolkit for Virtualization (MTV). -* Migrating Virtual Machines using the Migration Toolkit for Virtualization (MTV). - -## Testing - -[tox](https://tox.wiki) is used to perform tests and verification of this collection. - -The following commands can be used to execute the various types of tests implemented: - -```shell -tox -av # lists all tests - -tox # run them all - -tox -e # run specific one - -tox -f sanity --ansible -c tox-ansible.ini # run tox-ansible that does our ansible-test sanity suite -``` - -## Support - -The [Ansible Forum](https://forum.ansible.com/tag/openshift_migrate) can be used for additional questions and issues related to this collection. - -## License - -GNU General Public License v3.0 or later. - -See the [LICENSE](https://www.gnu.org/licenses/gpl-3.0.en.html) to see the full text. diff --git a/roles/mtv_management/tasks/_mtv_storage_map.yml b/roles/mtv_management/tasks/_mtv_storage_map.yml index ab05c6c..175bc14 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,48 @@ 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 +92,16 @@ - 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] ...