-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding export vm as ovf role #55
Merged
mikemorency
merged 5 commits into
redhat-cop:main
from
mikemorency:mm-feature/ACA-1591-create-ovf
Jun 18, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- export_vm_as_ovf - added role, playbook, tests to export an exisiting VM from VCenter or ESXi as an OVF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- name: Export VM as OVF File | ||
hosts: all | ||
gather_facts: false | ||
|
||
roles: | ||
- role: cloud.vmware_ops.export_vm_as_ovf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Export VM As OVF Role | ||
|
||
A role to export a VM from VCenter or ESXi as an OVF. The VM is exported to the local filesystem of the host running the tasks (anisble_host). | ||
|
||
## Requirements | ||
|
||
N/A | ||
|
||
## Role Variables | ||
### Auth | ||
- **export_vm_as_ovf_username**: | ||
- The vSphere vCenter username. | ||
|
||
- **export_vm_as_ovf_password**: | ||
- The vSphere vCenter password. | ||
|
||
- **export_vm_as_ovf_hostname**: | ||
- The hostname or IP address of the vSphere vCenter. | ||
|
||
- **export_vm_as_ovf_validate_certs** | ||
- Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted. | ||
|
||
- **export_vm_as_ovf_cluster_name**: | ||
- The name of the cluster in vSphere vCenter that contains the VM. | ||
|
||
- **export_vm_as_ovf_datacenter_name**: | ||
- The name of the datacenter in vSphere vCenter which contains the VM. | ||
|
||
- **export_vm_as_ovf_port**: | ||
- str or int, The port to use to authenticate to the vSphere vCenter which contains the VM. | ||
|
||
### VM Options | ||
- **export_vm_as_ovf_vm_datacenter**: | ||
- str, The name of the datacenter that contains the VM that should be exported. | ||
|
||
- **export_vm_as_ovf_vm_folder**: | ||
- str, The VCenter folder that contains the VM that should be exported. This should be the full folder path | ||
|
||
- **export_vm_as_ovf_vm_moid**: | ||
- str, The MOID of the VM that should be exported. | ||
- One of `export_vm_as_ovf_vm_uuid`, `export_vm_as_ovf_vm_name`, or `export_vm_as_ovf_vm_moid` needs to be defined. | ||
|
||
- **export_vm_as_ovf_vm_name**: | ||
- str, The name of the VM that should be exported. | ||
- One of `export_vm_as_ovf_vm_uuid`, `export_vm_as_ovf_vm_name`, or `export_vm_as_ovf_vm_moid` needs to be defined. | ||
|
||
- **export_vm_as_ovf_vm_uuid**: | ||
- str, The UUID of the VM that should be exported. | ||
- One of `export_vm_as_ovf_vm_uuid`, `export_vm_as_ovf_vm_name`, or `export_vm_as_ovf_vm_moid` needs to be defined. | ||
|
||
### Export Options | ||
- **export_vm_as_ovf_download_timeout**: | ||
- int, The maximum number of seconds that the OVF export process can take before a timeout error is thrown. | ||
|
||
- **export_vm_as_ovf_export_dir**: | ||
- str, Required. The local path to the directory where the OVF file should be created. | ||
- If the path does not exist, it will be created | ||
|
||
- **export_vm_as_ovf_export_with_extra_config**: | ||
- bool, If true any extra configuration settings applied to the VM will be included in the exported OVF | ||
|
||
- **export_vm_as_ovf_export_with_images**: | ||
- bool, If true any ISO files attached to the VM will be included in the exported OVF | ||
|
||
### Other | ||
- **export_vm_as_ovf_proxy_host**: | ||
- str, The hostname of a proxy host that should be used for all HTTPs communication by the role. Optional | ||
|
||
- **export_vm_as_ovf_proxy_port**: | ||
- str, The port of a proxy host that should be used for all HTTPs communication by the role. Optional | ||
|
||
|
||
## Dependencies | ||
|
||
- community.vmware | ||
|
||
## Example Playbook | ||
```yaml | ||
--- | ||
- name: Export VM To Lolcahost | ||
hosts: localhost | ||
gather_facts: false | ||
|
||
roles: | ||
- role: cloud.vmware_ops.export_vm_as_ovf | ||
export_vm_as_ovf_vm_name: my-test-vm | ||
export_vm_as_ovf_export_dir: /tmp/my-test-vm-ovf | ||
export_vm_as_ovf_datacenter: DC1 | ||
export_vm_as_ovf_hostname: <> | ||
export_vm_as_ovf_password: <> | ||
export_vm_as_ovf_username: <> | ||
|
||
``` | ||
## License | ||
|
||
GNU General Public License v3.0 or later | ||
|
||
See [LICENCE](https://github.com/ansible-collections/cloud.aws_troubleshooting/blob/main/LICENSE) to see the full text. | ||
|
||
## Author Information | ||
|
||
- Ansible Cloud Content Team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
- name: Check Mandatory Variables Are Defined | ||
ansible.builtin.assert: | ||
that: | ||
- export_vm_as_ovf_hostname is defined | ||
- export_vm_as_ovf_username is defined | ||
- export_vm_as_ovf_password is defined | ||
- export_vm_as_ovf_export_dir is defined | ||
- >- | ||
export_vm_as_ovf_vm_name is defined or | ||
export_vm_as_ovf_vm_uuid is defined or | ||
export_vm_as_ovf_vm_moid is defined | ||
quiet: true | ||
fail_msg: Variable must be set when using this role. | ||
|
||
- name: Export VM As OVF | ||
community.vmware.vmware_export_ovf: | ||
hostname: "{{ export_vm_as_ovf_hostname }}" | ||
username: "{{ export_vm_as_ovf_username }}" | ||
password: "{{ export_vm_as_ovf_password }}" | ||
validate_certs: "{{ export_vm_as_ovf_validate_certs | default(omit) }}" | ||
port: "{{ export_vm_as_ovf_port | default(omit) }}" | ||
proxy_host: "{{ export_vm_as_ovf_proxy_host | default(omit) }}" | ||
proxy_port: "{{ export_vm_as_ovf_proxy_port | default(omit) }}" | ||
|
||
datacenter: "{{ export_vm_as_ovf_vm_datacenter_name | default(omit) }}" | ||
folder: "{{ export_vm_as_ovf_vm_folder | default(omit) }}" | ||
name: "{{ export_vm_as_ovf_vm_name | default(omit) }}" | ||
uuid: "{{ export_vm_as_ovf_vm_uuid | default(omit) }}" | ||
moid: "{{ export_vm_as_ovf_vm_moid | default(omit) }}" | ||
|
||
export_dir: "{{ export_vm_as_ovf_export_dir }}" | ||
export_with_images: "{{ export_vm_as_ovf_export_with_images | default(omit) }}" | ||
export_with_extraconfig: "{{ export_vm_as_ovf_export_with_extra_config | default(omit) }}" | ||
download_timeout: "{{ export_vm_as_ovf_download_timeout | default(omit) }}" |
17 changes: 17 additions & 0 deletions
17
tests/integration/targets/vmware_ops_export_vm_as_ovf_test/run.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- hosts: localhost | ||
gather_facts: no | ||
collections: | ||
- community.general | ||
|
||
tasks: | ||
- name: Import eco-vcenter credentials | ||
ansible.builtin.include_vars: | ||
file: ../../integration_config.yml | ||
tags: eco-vcenter-ci | ||
|
||
- name: Import Export VM As OVF role | ||
ansible.builtin.import_role: | ||
name: vmware_ops_export_vm_as_ovf_test | ||
tags: | ||
- eco-vcenter-ci |
14 changes: 14 additions & 0 deletions
14
tests/integration/targets/vmware_ops_export_vm_as_ovf_test/runme.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
source ../init.sh | ||
|
||
# Extract the ansible_tags from integration_config.yml | ||
ANSIBLE_TAGS=$(awk '/ansible_tags/ {print $2}' ../../integration_config.yml) | ||
|
||
# Check if the ANSIBLE_TAGS variable is set | ||
if [[ -n "$ANSIBLE_TAGS" ]]; then | ||
echo "ANSIBLE_TAGS is set to: $ANSIBLE_TAGS" | ||
exec ansible-playbook run.yml --tags "$ANSIBLE_TAGS" | ||
else | ||
echo "ANSIBLE_TAGS is not set for Eco vCenter. Running on simulator." | ||
exec ansible-playbook run.yml --tags integration-ci | ||
fi |
39 changes: 39 additions & 0 deletions
39
tests/integration/targets/vmware_ops_export_vm_as_ovf_test/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
- name: Test | ||
tags: | ||
- eco-vcenter-ci | ||
block: | ||
- name: Create Test VM | ||
community.vmware.vmware_guest: | ||
hostname: "{{ export_vm_as_ovf_hostname }}" | ||
username: "{{ export_vm_as_ovf_username }}" | ||
password: "{{ export_vm_as_ovf_password }}" | ||
validate_certs: false | ||
name: "{{ export_vm_as_ovf_vm_name }}" | ||
state: poweredoff | ||
folder: /Eco-Datacenter/vm/e2e-qe | ||
datacenter: "{{ export_vm_as_ovf_datacenter_name }}" | ||
disk: | ||
- size_gb: 5 | ||
type: thick | ||
autoselect_datastore: True | ||
hardware: | ||
memory_mb: 2000 | ||
num_cpus: 2 | ||
guest_id: rhel9_64Guest | ||
- name: Test Export VM As OVF | ||
ansible.builtin.import_role: | ||
name: cloud.vmware_ops.export_vm_as_ovf | ||
always: | ||
- name: Destroy Test VM | ||
community.vmware.vmware_guest: | ||
hostname: "{{ export_vm_as_ovf_hostname }}" | ||
username: "{{ export_vm_as_ovf_username }}" | ||
password: "{{ export_vm_as_ovf_password }}" | ||
validate_certs: false | ||
name: "{{ export_vm_as_ovf_vm_name }}" | ||
state: absent | ||
- name: Delete Exported OVF | ||
ansible.builtin.file: | ||
state: absent | ||
path: "{{ export_vm_as_ovf_export_dir }}" |
9 changes: 9 additions & 0 deletions
9
tests/integration/targets/vmware_ops_export_vm_as_ovf_test/vars/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
export_vm_as_ovf_hostname: "{{ vcenter_hostname }}" | ||
export_vm_as_ovf_username: "{{ vcenter_username }}" | ||
export_vm_as_ovf_password: "{{ vcenter_password }}" | ||
export_vm_as_ovf_validate_certs: false | ||
export_vm_as_ovf_datacenter_name: Eco-Datacenter | ||
|
||
export_vm_as_ovf_export_dir: /tmp/export_vm_as_ovf | ||
export_vm_as_ovf_vm_name: export-vm-as-ovf-test |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the vCenter UI this operation is called: deploy ovf template... maybe it is better to use the UI operation name. let's ask the others @machacekondra @shellymiron @elsapassaro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think that is the opposite operation, deploying ovf template means create a VM from an OVF
https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-17BEDA21-43F6-41F4-8FB2-E01D275FE9B4.html