Skip to content

Commit

Permalink
Fix CR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Danielle Barda <dbarda@redhat.com>
  • Loading branch information
bardielle committed Mar 6, 2024
1 parent c5e3c1e commit 671e983
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 198 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
3 changes: 0 additions & 3 deletions playbooks/provision_vm/manage_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 0 additions & 9 deletions playbooks/provision_vm/provisioning_vm_from_template.yml

This file was deleted.

9 changes: 0 additions & 9 deletions playbooks/provision_vm/provisioning_vm_from_vm.yml

This file was deleted.

3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion roles/create_vm_template/README.md

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
64 changes: 37 additions & 27 deletions roles/provision_vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions roles/provision_vm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
---
provision_vm_clone_from_template: false
provision_vm_clone_from_vm: false
89 changes: 40 additions & 49 deletions roles/provision_vm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pyVim
pyVmomi
pyVmomi>=6.7
podman
requests
File renamed without changes.
64 changes: 0 additions & 64 deletions tests/integration/targets/provision_vm_test/mock.json

This file was deleted.

2 changes: 0 additions & 2 deletions tests/integration/targets/provision_vm_test/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
gather_facts: no
collections:
- community.general
vars_files:
- vars.yml

tasks:
- name: Vcsim
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/targets/provision_vm_test/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,3 +19,4 @@
provision_vm_hardware:
memory_mb: 512
num_cpus: 4
provision_vm_guest_id: "centos64Guest"
12 changes: 0 additions & 12 deletions tests/integration/targets/provision_vm_test/vars.yml

This file was deleted.

0 comments on commit 671e983

Please sign in to comment.