From 75a1fa402a59d39184c8f809150d9e8bfe4eea61 Mon Sep 17 00:00:00 2001 From: Danielle Barda Date: Sun, 3 Mar 2024 12:45:21 +0200 Subject: [PATCH] fixing CI Signed-off-by: Danielle Barda --- .github/workflows/test.yml | 16 ++++- Makefile | 2 +- playbooks/provision_vm/manage_vm.yml | 4 +- .../provisioning_vm_from_template.yml | 4 +- .../provision_vm/provisioning_vm_from_vm.yml | 5 +- requirements.txt | 2 + roles/create_vm_template/README.md | 70 +------------------ roles/create_vm_template/defaults/main.yml | 1 - roles/create_vm_template/tasks/main.yml | 5 -- roles/provision_vm/README.md | 10 +-- roles/provision_vm/tasks/main.yml | 46 ++++++------ tests/integration/requirements.txt | 2 + .../targets/prepare_soap/tasks/main.yml | 3 +- .../targets/provision_vm_test/tasks/main.yml | 11 ++- .../targets/provision_vm_test/vars.yml | 3 - 15 files changed, 64 insertions(+), 120 deletions(-) create mode 100644 requirements.txt create mode 100644 tests/integration/requirements.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17b05f81..69fd663d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,9 +22,19 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 with: - path: ansible_collections/redhat_cop/vmware_ops + path: ansible_collections/cloud/vmware_ops + + - name: Install requirements + run: | + ansible-galaxy collection install -r requirements.yml + working-directory: ansible_collections/cloud/vmware_ops + + - name: Install python packages from requirements txt file + run: | + pip3 install -r requirements.txt + working-directory: ansible_collections/cloud/vmware_ops - name: Run run: | - make integration - working-directory: ansible_collections/redhat_cop/vmware_ops + ANSIBLE_PYTHON_INTERPRETER=/usr/bin/python make integration + working-directory: ansible_collections/cloud/vmware_ops diff --git a/Makefile b/Makefile index 9c7ed7f4..eb629cd2 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ integration: - ansible-test integration --no-temp-workdir security_test + ansible-test integration --no-temp-workdir diff --git a/playbooks/provision_vm/manage_vm.yml b/playbooks/provision_vm/manage_vm.yml index 70d52711..f2d3b7f1 100644 --- a/playbooks/provision_vm/manage_vm.yml +++ b/playbooks/provision_vm/manage_vm.yml @@ -5,5 +5,5 @@ roles: - role: cloud.vmware_ops.provision_vm vars: - clone_from_template: false - clone_from_vm: false \ No newline at end of file + provision_vm_clone_from_template: false + provision_vm_clone_from_vm: false diff --git a/playbooks/provision_vm/provisioning_vm_from_template.yml b/playbooks/provision_vm/provisioning_vm_from_template.yml index 7c20fe2c..3aa0603f 100644 --- a/playbooks/provision_vm/provisioning_vm_from_template.yml +++ b/playbooks/provision_vm/provisioning_vm_from_template.yml @@ -5,5 +5,5 @@ roles: - role: cloud.vmware_ops.provision_vm vars: - clone_from_template: true - clone_from_vm: false + provision_vm_clone_from_template: true + provision_vm_clone_from_vm: false diff --git a/playbooks/provision_vm/provisioning_vm_from_vm.yml b/playbooks/provision_vm/provisioning_vm_from_vm.yml index ee37205c..d235e031 100644 --- a/playbooks/provision_vm/provisioning_vm_from_vm.yml +++ b/playbooks/provision_vm/provisioning_vm_from_vm.yml @@ -5,6 +5,5 @@ roles: - role: cloud.vmware_ops.provision_vm vars: - clone_from_template: false - clone_from_vm: true - + provision_vm_clone_from_template: false + provision_vm_clone_from_vm: true diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..64315ce0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pyVim +pyVmomi>=6.7 diff --git a/roles/create_vm_template/README.md b/roles/create_vm_template/README.md index 2da805a7..2fd9f957 100644 --- a/roles/create_vm_template/README.md +++ b/roles/create_vm_template/README.md @@ -1,69 +1 @@ -Provision virtual machine -================ - -A role to provision a virtual machine, create associated resources if they don’t exist (subnets, vCPU, memory configuration, storage configuration, etc) -This includes cloning and building from VM templates -Boot a VM from these types: -* Windows Server -* RHEL8 -* RHEL9 - - -Requirements ------------- - -vCenter logged in permission - -Role Variables --------------- - -* **vcenter_hostname** (str): (Required) -* **vcenter_username** (str): (Required) -* **vcenter_password** (str): (Required) -* **vcenter_validate_certs** (str): (Required) -* **provision_virtual_machine_operation** (str): (Required) Operation to perform. Valid values are: - clone_an_existing_vm, clone_template_to_template, clone_vm_to_template, create_new_vm, create_vm_from_template, - deploy_from_template. - -Dependencies ------------- - -N/A - -Example Playbook ----------------- - -All the variables defined in section [Role Variables](#role-variables) can be defined inside the ``vars.yml`` file. - -Create a ``playbook.yml`` file like this: - -``` ---- -- hosts: localhost - gather_facts: true - - tasks: - - name: Provision a VM - ansible.builtin.import_role: - name: cloud.vmware_ops.provision_virtual_machine - vars: - aa: "{{ }}" -``` - -Run the playbook: - -```shell -ansible-playbook playbook.yml -e "@vars.yml" -``` - -License -------- - -GNU General Public License v3.0 or later - -See [LICENCE](https://github.com/ansible-collections/cloud.vmware_ops/blob/main/LICENSE) to see the full text. - -Author Information ------------------- - -- ?? \ No newline at end of file +TBD \ No newline at end of file diff --git a/roles/create_vm_template/defaults/main.yml b/roles/create_vm_template/defaults/main.yml index 73b314ff..e69de29b 100644 --- a/roles/create_vm_template/defaults/main.yml +++ b/roles/create_vm_template/defaults/main.yml @@ -1 +0,0 @@ ---- \ No newline at end of file diff --git a/roles/create_vm_template/tasks/main.yml b/roles/create_vm_template/tasks/main.yml index 4fc1bd7c..e69de29b 100644 --- a/roles/create_vm_template/tasks/main.yml +++ b/roles/create_vm_template/tasks/main.yml @@ -1,5 +0,0 @@ ---- -# vm name or vm template -- name: Create VM or template - ansible.builtin.include_tasks: "clone_vm_to_template.yml" - diff --git a/roles/provision_vm/README.md b/roles/provision_vm/README.md index 61a137d6..9293a16b 100644 --- a/roles/provision_vm/README.md +++ b/roles/provision_vm/README.md @@ -1,5 +1,5 @@ # Provision virtual machine -A role to provision a virtual machine, create associated resources if they don’t exist (subnets, vCPU, memory configuration, storage configuration, etc) +A role to provision a virtual machine, create associated resources if they don't exist (subnets, vCPU, memory configuration, storage configuration, etc) This includes cloning and building from VM templates. @@ -73,7 +73,7 @@ N/A - **provision_vm_folder** (string): Destination folder, absolute path to find an existing guest or create the new guest. - The folder should include the datacenter. ESXi’s datacenter is ha-datacenter. + The folder should include the datacenter. ESXi's datacenter is ha-datacenter. This parameter is case sensitive. If multiple machines are found with same name, this parameter is used to identify uniqueness of the virtual machine. @@ -415,7 +415,7 @@ N/A Valid values are referenced here: https://code.vmware.com/apis/358/doc/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html - **provision_vm_hardware** (dictionary): - Manage virtual machine’s hardware attributes. + Manage virtual machine's hardware attributes. All parameters case sensitive. Keys: * hotadd_cpu: @@ -532,7 +532,7 @@ N/A - **provision_vm_state** (string): Specify the state the virtual machine should be in. If present and virtual machine exists, ensure the virtual machine configurations conforms to task arguments. - If absent and virtual machine exists, then the specified virtual machine is removed with it’s associated components. + If absent and virtual machine exists, then the specified virtual machine is removed with it's associated components. If set to one of poweredon, powered-on, poweredoff, powered-off, present, restarted, suspended and virtual machine does not exists, virtual machine is deployed with the given parameters. If set to poweredon or powered-on and virtual machine exists with powerstate other than powered on, then the specified virtual machine is powered on. If set to poweredoff or powered-off and virtual machine exists with powerstate other than powered off, then the specified virtual machine is powered off. @@ -612,7 +612,7 @@ N/A A list of networks (in the order of the NICs). Removing NICs is not allowed, while reconfiguring the virtual machine. All parameters and VMware object names are case sensitive. - The type, ip, netmask, gateway, domain, dns_servers options don’t set to a guest when creating a blank new virtual machine. They are set by the customization via vmware-tools. If you want to set the value of the options to a guest, you need to clone from a template with installed OS and vmware-tools(also Perl when Linux). + The type, ip, netmask, gateway, domain, dns_servers options don't set to a guest when creating a blank new virtual machine. They are set by the customization via vmware-tools. If you want to set the value of the options to a guest, you need to clone from a template with installed OS and vmware-tools(also Perl when Linux). Element keys: * name: type: str diff --git a/roles/provision_vm/tasks/main.yml b/roles/provision_vm/tasks/main.yml index cdae516d..773257fb 100644 --- a/roles/provision_vm/tasks/main.yml +++ b/roles/provision_vm/tasks/main.yml @@ -1,15 +1,15 @@ --- -- name: Fail if cluster and esxi_hostname both weren't set or both were set - when: ("{{ cluster }}" is defined and "{{ esxi_hostname }}" is defined) or ("{{ cluster }}" is not defined and "{{ esxi_hostname }}" is not defined) +- name: Fail if provision_vm_cluster and provision_vm_esxi_hostname both weren't set or both were set + when: ( provision_vm_cluster is defined and provision_vm_esxi_hostname is defined ) or ( provision_vm_cluster is not defined and provision_vm_esxi_hostname is not defined) # noqa: yaml[line-length] ansible.builtin.fail: - msg: esxi_hostname and cluster are mutually exclusive parameters + msg: provision_vm_esxi_hostname and provision_vm_cluster are mutually exclusive parameters - name: Create or update the VM community.vmware.vmware_guest: - hostname: "{{ provision_vm_hostname }}" + hostname: "{{ provision_vm_hostname }}" username: "{{ provision_vm_username }}" password: "{{ provision_vm_password }}" - validate_certs: "{{ omit if provision_vm_validate_certs is not defined else provision_vm_validate_certs}}" + validate_certs: "{{ omit if provision_vm_validate_certs is not defined else provision_vm_validate_certs }}" port: "{{ omit if provision_vm_port is not defined else provision_vm_port }}" proxy_host: "{{ omit if provision_vm_proxy_host is not defined else provision_vm_proxy_host }}" @@ -19,22 +19,22 @@ uuid: "{{ omit if provision_vm_uuid is not defined else provision_vm_uuid }}" # compute resource: - cluster: "{{ omit if provision_vm_cluster not defined else provision_vm_cluster }}" - esxi_hostname: "{{ omit if provision_vm_esxi_hostname is not defined else provision_vm_esxi_hostname}}" - datacenter: "{{ omit if provision_vm_datacenter is not defined else provision_vm_datacenter}}" - folder: "{{ omit if provision_vm_folder is not defined else provision_vm_folder}}" - datastore: "{{ omit if provision_vm_datastore is not defined else provision_vm_datastore}}" - resource_pool: "{{ omit if provision_vm_resource_pool is not defined else provision_vm_resource_pool}}" + cluster: "{{ omit if provision_vm_cluster is not defined else provision_vm_cluster }}" + esxi_hostname: "{{ omit if provision_vm_esxi_hostname is not defined else provision_vm_esxi_hostname }}" + datacenter: "{{ omit if provision_vm_datacenter is not defined else provision_vm_datacenter }}" + folder: "{{ omit if provision_vm_folder is not defined else provision_vm_folder }}" + datastore: "{{ omit if provision_vm_datastore is not defined else provision_vm_datastore }}" + resource_pool: "{{ omit if provision_vm_resource_pool is not defined else provision_vm_resource_pool }}" # for cloning VM - template: "{{ provision_vm_template }}" + template: "{{ omit if provision_vm_template is not defined else provision_vm_template }}" convert: "{{ omit if provision_vm_convert is not defined else provision_vm_convert }}" linked_clone: "{{ omit if provision_vm_linked_clone is not defined else provision_vm_linked_clone }}" snapshot_src: "{{ omit if provision_vm_snapshot_src is not defined else provision_vm_snapshot_src }}" # optional: - advanced_settings: "{{ omit if provision_vm_advanced_settings is not defined else provision_vm_advanced_settings}}" - annotation: "{{ omit if provision_vm_annotation is not defined else provision_vm_annotation}}" + advanced_settings: "{{ omit if provision_vm_advanced_settings is not defined else provision_vm_advanced_settings }}" + annotation: "{{ omit if provision_vm_annotation is not defined else provision_vm_annotation }}" cdrom: "{{ omit if provision_vm_cdrom is not defined else provision_vm_cdrom }}" customization: "{{ omit if provision_vm_customization is not defined else provision_vm_customization }}" customization_spec: "{{ omit if provision_vm_customization_spec is not defined else provision_vm_customization_spec }}" @@ -45,16 +45,16 @@ force: "{{ omit if provision_vm_force is not defined else provision_vm_force }}" guest_id: "{{ omit if provision_vm_guest_id is not defined else provision_vm_guest_id }}" hardware: "{{ omit if provision_vm_hardware is not defined else provision_vm_hardware }}" - state: "{{ omit if provision_vm_state is not defined else provision_vm_state}}" - state_change_timeout: "{{ omit if provision_vm_state_change_timeout is not defined else provision_vm_state_change_timeout}}" - vapp_properties: "{{ omit if provision_vm_vapp_properties is not defined else provision_vm_vapp_properties}}" - wait_for_customization: "{{ omit if provision_vm_wait_for_customization is not defined else provision_vm_wait_for_customization}}" - wait_for_customization_timeout: "{{ omit if provision_vm_wait_for_customization_timeout is not defined else provision_vm_wait_for_customization_timeout}}" - wait_for_ip_address: "{{ omit if provision_vm_wait_for_ip_address is not defined else provision_vm_wait_for_ip_address}}" - wait_for_ip_address_timeout: "{{ omit if provision_vm_wait_for_ip_address_timeout is not defined else provision_vm_wait_for_ip_address_timeout}}" + state: "{{ omit if provision_vm_state is not defined else provision_vm_state }}" + state_change_timeout: "{{ omit if provision_vm_state_change_timeout is not defined else provision_vm_state_change_timeout }}" + vapp_properties: "{{ omit if provision_vm_vapp_properties is not defined else provision_vm_vapp_properties }}" + wait_for_customization: "{{ omit if provision_vm_wait_for_customization is not defined else provision_vm_wait_for_customization }}" + wait_for_customization_timeout: "{{ omit if provision_vm_wait_for_customization_timeout is not defined else provision_vm_wait_for_customization_timeout }}" + wait_for_ip_address: "{{ omit if provision_vm_wait_for_ip_address is not defined else provision_vm_wait_for_ip_address }}" + wait_for_ip_address_timeout: "{{ omit if provision_vm_wait_for_ip_address_timeout is not defined else provision_vm_wait_for_ip_address_timeout }}" networks: "{{ omit if provision_vm_networks is not defined else provision_vm_networks }}" nvdimm: "{{ omit if provision_vm_nvdimm is not defined else provision_vm_nvdimm }}" - use_instance_uuid: "{{ omit if provision_vm_use_instance_uuid is not defined else provision_vm_use_instance_uuid }}" + use_instance_uuid: "{{ omit if provision_vm_use_instance_uuid is not defined else provision_vm_use_instance_uuid }}" name_match: "{{ omit if provision_vm_name_match is not defined else provision_vm_name_match }}" is_template: false @@ -62,4 +62,4 @@ - name: Print VM information ansible.builtin.debug: - var: my_vm \ No newline at end of file + var: my_vm diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt new file mode 100644 index 00000000..8aa28164 --- /dev/null +++ b/tests/integration/requirements.txt @@ -0,0 +1,2 @@ +pyVim +pyVmomi diff --git a/tests/integration/targets/prepare_soap/tasks/main.yml b/tests/integration/targets/prepare_soap/tasks/main.yml index b2c4321c..0166e818 100644 --- a/tests/integration/targets/prepare_soap/tasks/main.yml +++ b/tests/integration/targets/prepare_soap/tasks/main.yml @@ -2,8 +2,7 @@ - name: Install dependencies ansible.builtin.pip: name: - - requests - - aiohttp + - pyVmomi - name: Run rest community.docker.docker_container: diff --git a/tests/integration/targets/provision_vm_test/tasks/main.yml b/tests/integration/targets/provision_vm_test/tasks/main.yml index ee3bf94a..cbd3b86c 100644 --- a/tests/integration/targets/provision_vm_test/tasks/main.yml +++ b/tests/integration/targets/provision_vm_test/tasks/main.yml @@ -1,4 +1,13 @@ --- -- name: Security role +- name: Provision VM ansible.builtin.import_role: name: cloud.vmware_ops.provision_vm + vars: + provision_vm_hostname: "test" + provision_vm_username: "test" + provision_vm_password: "test" + provision_vm_validate_certs: false + provision_vm_cluster: "C0" + provision_vm_datacenter: "DC0" + provision_vm_folder: "folder" + provision_vm_vm_name: "vm-test" diff --git a/tests/integration/targets/provision_vm_test/vars.yml b/tests/integration/targets/provision_vm_test/vars.yml index ffe33c40..8f47f17a 100644 --- a/tests/integration/targets/provision_vm_test/vars.yml +++ b/tests/integration/targets/provision_vm_test/vars.yml @@ -10,6 +10,3 @@ provision_vm_cluster: "cluster_test" provision_vm_datacenter: "dc_test" provision_vm_folder: "folder_test" provision_vm_guest_id: "centos64Guest" - - -