diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index b8bf70c3..140a5b55 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -17,9 +17,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install requirements - run: ansible-galaxy collection install -r requirements.yml - - name: Run ansible-lint uses: ansible/ansible-lint@v6.22.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce902cf7..d524d5a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,16 +25,6 @@ jobs: with: 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: | ANSIBLE_PYTHON_INTERPRETER=/usr/bin/python make integration diff --git a/Makefile b/Makefile index eb629cd2..ce781690 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,11 @@ -integration: +.PHONY: install-python-packages +install-python-packages: + pip3 install -r tests/integration/requirements.txt + +.PHONY: install-ansible-collections +install-ansible-collections: + ansible-galaxy collection install -r tests/integration/requirements.yml + +.PHONY: integration +integration: install-python-packages install-ansible-collections ansible-test integration --no-temp-workdir diff --git a/galaxy.yml b/galaxy.yml index d86a1a45..741758c0 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -17,5 +17,6 @@ build_ignore: - .gitignore - changelogs/.plugin-cache.yaml dependencies: { - "vmware.vmware_rest": ">=2.3.1" + "vmware.vmware_rest": ">=2.3.1", + "community.vmware": ">=4.2.0", } diff --git a/playbooks/provision_vm/manage_vm.yml b/playbooks/provision_vm/manage_vm.yml index f2d3b7f1..572ad4be 100644 --- a/playbooks/provision_vm/manage_vm.yml +++ b/playbooks/provision_vm/manage_vm.yml @@ -4,6 +4,3 @@ gather_facts: false roles: - role: cloud.vmware_ops.provision_vm - vars: - 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 deleted file mode 100644 index 3aa0603f..00000000 --- a/playbooks/provision_vm/provisioning_vm_from_template.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- name: Playbook to provision a new VM from template on VMware - hosts: all - gather_facts: false - roles: - - role: cloud.vmware_ops.provision_vm - vars: - 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 deleted file mode 100644 index d235e031..00000000 --- a/playbooks/provision_vm/provisioning_vm_from_vm.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- name: Playbook to provision a new VM from an existing VM on VMware - hosts: all - gather_facts: false - roles: - - role: cloud.vmware_ops.provision_vm - vars: - provision_vm_clone_from_template: false - provision_vm_clone_from_vm: true diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 09c1e9a0..00000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pyVim -pyVmomi>=6.7 -podman diff --git a/roles/create_vm_template/README.md b/roles/create_vm_template/README.md deleted file mode 100644 index 2fd9f957..00000000 --- a/roles/create_vm_template/README.md +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index e69de29b..00000000 diff --git a/roles/create_vm_template/tasks/clone_template_to_template.yml b/roles/create_vm_template/tasks/clone_template_to_template.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/roles/create_vm_template/tasks/clone_vm_to_template.yml b/roles/create_vm_template/tasks/clone_vm_to_template.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/roles/create_vm_template/tasks/main.yml b/roles/create_vm_template/tasks/main.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/roles/provision_vm/README.md b/roles/provision_vm/README.md index 9293a16b..30b6d399 100644 --- a/roles/provision_vm/README.md +++ b/roles/provision_vm/README.md @@ -21,14 +21,22 @@ N/A - **provision_vm_validate_certs** (boolean) - Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted. -### Provisioning a VM -- **provision_vm_clone_from_vm** (boolean): - Create from an existing VM +- **provision_vm_port** (integer): + The port number of the vSphere vCenter or ESXi server. + If the value is not specified in the task, the value of environment variable VMWARE_PORT will be used instead. + Default: 443 -- **provision_vm_clone_from_template** (boolean): - Create from template VM +- **provision_vm_proxy_host** (string): + Address of a proxy that will receive all HTTPS requests and relay them. + The format is a hostname or a IP. + If the value is not specified in the task, the value of environment variable VMWARE_PROXY_HOST will be used instead. -- **provision_vm_vm_name** (string, Required): +- **provision_vm_proxy_port** (integer): + Port of the HTTP proxy that will receive all HTTPS requests and relay them. + If the value is not specified in the task, the value of environment variable VMWARE_PROXY_PORT will be used instead. + +### Provisioning a VM +- **provision_vm_name** (string, Required): Name of the virtual machine to work with. Virtual machine names in vCenter are not necessarily unique, which may be problematic, see O(name_match). If multiple virtual machines with same name exists, then O(folder) is required parameter to @@ -43,28 +51,14 @@ N/A If virtual machine does not exists, then this parameter is ignored. Please note that a supplied UUID will be ignored on virtual machine creation, as VMware creates the UUID internally. -- **provision_vm_port** (integer): - The port number of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable VMWARE_PORT will be used instead. - Default: 443 - -- **provision_vm_proxy_host** (string): - Address of a proxy that will receive all HTTPS requests and relay them. - The format is a hostname or a IP. - If the value is not specified in the task, the value of environment variable VMWARE_PROXY_HOST will be used instead. - -- **provision_vm_proxy_port** (integer): - Port of the HTTP proxy that will receive all HTTPS requests and relay them. - If the value is not specified in the task, the value of environment variable VMWARE_PROXY_PORT will be used instead. - - **provision_vm_cluster** (String): The cluster name where the virtual machine will run. - - **provision_vm_esxi_hostname** (string): - The ESXi hostname where the virtual machine will run. - This is a required parameter, if cluster is not set. - esxi_hostname and cluster are mutually exclusive parameters. - This parameter is case sensitive. +- **provision_vm_esxi_hostname** (string): + The ESXi hostname where the virtual machine will run. + This is a required parameter, if cluster is not set. + esxi_hostname and cluster are mutually exclusive parameters. + This parameter is case sensitive. - **provision_vm_datacenter** (string): Destination datacenter for the deploy operation. @@ -778,9 +772,25 @@ Create a ``playbook.yml`` file like this: tasks: - name: Provision a VM ansible.builtin.import_role: - name: cloud.vmware_ops.provision_virtual_machine + name: cloud.vmware_ops.provision_vm vars: - aa: "{{ }}" + provision_vm_hostname: "test" + provision_vm_username: "test" + provision_vm_password: "test" + provision_vm_validate_certs: false + provision_vm_cluster: "DC0_C0" + provision_vm_folder: "/DC0/vm" + provision_vm_datacenter: "DC0" + provision_vm_name: "vm-test" + provision_vm_port: "8989" + provision_vm_disk: + - size_gb: 10 + type: thin + datastore: "LocalDS_0" + provision_vm_hardware: + memory_mb: 512 + num_cpus: 4 + provision_vm_guest_id: "centos64Guest" ``` Run the playbook: diff --git a/roles/provision_vm/defaults/main.yml b/roles/provision_vm/defaults/main.yml index 9e0c251f..ed97d539 100644 --- a/roles/provision_vm/defaults/main.yml +++ b/roles/provision_vm/defaults/main.yml @@ -1,3 +1 @@ --- -provision_vm_clone_from_template: false -provision_vm_clone_from_vm: false diff --git a/roles/provision_vm/tasks/main.yml b/roles/provision_vm/tasks/main.yml index 773257fb..b9690036 100644 --- a/roles/provision_vm/tasks/main.yml +++ b/roles/provision_vm/tasks/main.yml @@ -1,65 +1,56 @@ --- -- 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: provision_vm_esxi_hostname and provision_vm_cluster are mutually exclusive parameters - -- name: Create or update the VM +- name: Manage VM community.vmware.vmware_guest: 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: "{{ provision_vm_validate_certs | d(omit) }}" - 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 }}" - proxy_port: "{{ omit if provision_vm_proxy_port is not defined else provision_vm_proxy_port }}" + port: "{{ provision_vm_port | d(omit) }}" + proxy_host: "{{ provision_vm_proxy_host | d(omit) }}" + proxy_port: "{{ provision_vm_proxy_port | d(omit) }}" - name: "{{ provision_vm_vm_name }}" - uuid: "{{ omit if provision_vm_uuid is not defined else provision_vm_uuid }}" + name: "{{ provision_vm_name }}" + uuid: "{{ provision_vm_uuid | d(omit) }}" # compute resource: - 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 }}" + cluster: "{{ provision_vm_cluster | d(omit) }}" + esxi_hostname: "{{ provision_vm_esxi_hostname | d(omit) }}" + datacenter: "{{ provision_vm_datacenter | d(omit) }}" + folder: "{{ provision_vm_folder | d(omit) }}" + datastore: "{{ provision_vm_datastore | d(omit) }}" + resource_pool: "{{ provision_vm_resource_pool | d(omit) }}" # for cloning VM - 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 }}" + template: "{{ provision_vm_template | d(omit) }}" + convert: "{{ provision_vm_convert | d(omit) }}" + linked_clone: "{{ provision_vm_linked_clone | d(omit) }}" + snapshot_src: "{{ provision_vm_snapshot_src | d(omit) }}" # 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 }}" - 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 }}" - customvalues: "{{ omit if provision_vm_customvalues is not defined else provision_vm_customvalues }}" - delete_from_inventory: "{{ omit if provision_vm_delete_from_inventory is not defined else provision_vm_delete_from_inventory }}" - disk: "{{ omit if provision_vm_disk is not defined else provision_vm_disk }}" - encryption: "{{ omit if provision_vm_encryption is not defined else provision_vm_encryption }}" - 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 }}" - 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 }}" - name_match: "{{ omit if provision_vm_name_match is not defined else provision_vm_name_match }}" + advanced_settings: "{{ provision_vm_advanced_settings | d(omit) }}" + annotation: "{{ provision_vm_annotation | d(omit) }}" + cdrom: "{{ provision_vm_cdrom | d(omit) }}" + customization: "{{ provision_vm_customization | d(omit) }}" + customization_spec: "{{ provision_vm_customization_spec | d(omit) }}" + customvalues: "{{ provision_vm_customvalues | d(omit) }}" + delete_from_inventory: "{{ provision_vm_delete_from_inventory | d(omit) }}" + disk: "{{ provision_vm_disk | d(omit) }}" + encryption: "{{ provision_vm_encryption | d(omit) }}" + force: "{{ provision_vm_force | d(omit) }}" + guest_id: "{{ provision_vm_guest_id | d(omit) }}" + hardware: "{{ provision_vm_hardware | d(omit) }}" + state: "{{ provision_vm_state | d(omit) }}" + state_change_timeout: "{{ provision_vm_state_change_timeout | d(omit) }}" + vapp_properties: "{{ provision_vm_vapp_properties | d(omit) }}" + wait_for_customization: "{{ provision_vm_wait_for_customization | d(omit) }}" + wait_for_customization_timeout: "{{ provision_vm_wait_for_customization_timeout | d(omit) }}" + wait_for_ip_address: "{{ provision_vm_wait_for_ip_address | d(omit) }}" + wait_for_ip_address_timeout: "{{ provision_vm_wait_for_ip_address_timeout | d(omit) }}" + networks: "{{ provision_vm_networks | d(omit) }}" + nvdimm: "{{ provision_vm_nvdimm | d(omit) }}" + use_instance_uuid: "{{ provision_vm_use_instance_uuid | d(omit) }}" + name_match: "{{ provision_vm_name_match | d(omit) }}" is_template: false register: my_vm - -- name: Print VM information - ansible.builtin.debug: - var: my_vm diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt index 8aa28164..e2e3b69b 100644 --- a/tests/integration/requirements.txt +++ b/tests/integration/requirements.txt @@ -1,2 +1,4 @@ pyVim -pyVmomi +pyVmomi>=6.7 +podman +requests diff --git a/requirements.yml b/tests/integration/requirements.yml similarity index 100% rename from requirements.yml rename to tests/integration/requirements.yml diff --git a/tests/integration/targets/provision_vm_test/mock.json b/tests/integration/targets/provision_vm_test/mock.json deleted file mode 100644 index 2ef2cbfa..00000000 --- a/tests/integration/targets/provision_vm_test/mock.json +++ /dev/null @@ -1,64 +0,0 @@ -[ -{ - "httpRequest": { - "method": "POST", - "path": "/rest/com/vmware/cis/session" - }, - "httpResponse": { - "statusCode": 200, - "body": {"value": "72300ca9ff16c5743fa0a6328c8570ce"} - } -}, -{ - "httpRequest": { - "method": "PUT", - "path": "/api/appliance/access/(consolecli|dcui|shell|ssh)" - }, - "httpResponse": { - "statusCode": 200, - "headers": { - "Content-Type": "application/json" - }, - "body": "{}" - } -}, -{ - "httpRequest": { - "method": "GET", - "path": "/api/appliance/access/(consolecli|dcui|shell|ssh)" - }, - "httpResponse": { - "statusCode": 200, - "headers": { - "Content-Type": "application/json" - }, - "body": "true" - } -}, -{ - "httpRequest": { - "method" : "GET", - "path" : "/api/appliance/networking/firewall/inbound" - }, - "httpResponse": { - "statusCode": 200, - "headers": { - "Content-Type": "application/json" - }, - "body": [{}] - } -}, -{ - "httpRequest": { - "method" : "PUT", - "path" : "/api/appliance/networking/firewall/inbound" - }, - "httpResponse": { - "statusCode": 200, - "headers": { - "Content-Type": "application/json" - }, - "body": "{}" - } -} -] diff --git a/tests/integration/targets/provision_vm_test/run.yml b/tests/integration/targets/provision_vm_test/run.yml index 5ddf326d..69481b4a 100644 --- a/tests/integration/targets/provision_vm_test/run.yml +++ b/tests/integration/targets/provision_vm_test/run.yml @@ -2,8 +2,6 @@ gather_facts: no collections: - community.general - vars_files: - - vars.yml tasks: - name: Vcsim diff --git a/tests/integration/targets/provision_vm_test/tasks/main.yml b/tests/integration/targets/provision_vm_test/tasks/main.yml index eed7b754..47be9ce2 100644 --- a/tests/integration/targets/provision_vm_test/tasks/main.yml +++ b/tests/integration/targets/provision_vm_test/tasks/main.yml @@ -10,7 +10,7 @@ provision_vm_cluster: "DC0_C0" provision_vm_folder: "/DC0/vm" provision_vm_datacenter: "DC0" - provision_vm_vm_name: "vm-test" + provision_vm_name: "vm-test" provision_vm_port: "8989" provision_vm_disk: - size_gb: 10 @@ -19,3 +19,4 @@ provision_vm_hardware: memory_mb: 512 num_cpus: 4 + provision_vm_guest_id: "centos64Guest" diff --git a/tests/integration/targets/provision_vm_test/vars.yml b/tests/integration/targets/provision_vm_test/vars.yml deleted file mode 100644 index 8f47f17a..00000000 --- a/tests/integration/targets/provision_vm_test/vars.yml +++ /dev/null @@ -1,12 +0,0 @@ -mock_file: "provision_vm_test" - -provision_vm_hostname: "127.0.0.1:1080" -provision_vm_username: "user" -provision_vm_password: "pass" -provision_vm_validate_certs: false - -provision_vm_vm_name: "vm_test" -provision_vm_cluster: "cluster_test" -provision_vm_datacenter: "dc_test" -provision_vm_folder: "folder_test" -provision_vm_guest_id: "centos64Guest"