Skip to content

Commit

Permalink
upload iso to datastore (#120)
Browse files Browse the repository at this point in the history
* rebase branch

* add new line

* add ansible-test workflow yaml

* fixed podman version in  test workflow yaml

* fix yaml indentation
  • Loading branch information
OrrBG authored Jan 20, 2025
1 parent 849e788 commit acc23b7
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ jobs:
run: |
set -euxo pipefail
sudo apt-get update
# recent version of podman has a bug. Fix is waiting deployment
# see https://github.com/actions/runner-images/issues/7753
sudo apt-get install podman=3.4.4+ds1-1ubuntu1 --allow-downgrades
sudo apt-get install podman
- name: Checkout repo
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions changelogs/fragments/120-feature-upload-iso-to-datastore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- upload_iso_to_datastore - Created role intended for uploading local ISO files to a Datastore
7 changes: 7 additions & 0 deletions playbooks/upload_iso_to_datastore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Upload local ISO file to Datastore
hosts: all
gather_facts: false

roles:
- role: cloud.vmware_ops.upload_iso_to_datastore
111 changes: 111 additions & 0 deletions roles/upload_iso_to_datastore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# upload_iso_to_datastore
A role intended for uploading local ISO files to a Datastore.


## Dependencies

N/A


## Role Variables

### Auth

- **upload_iso_to_datastore_hostname** (str, required)
- The hostname or IP address of the vSphere vCenter or ESXi host.
- If this variable is not set, the collection level variable `vmware_ops_hostname` will be used. If that variable is not set, the environment variable `VMWARE_HOST` will be used. At least one of these variables must be set to use this role.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

- **upload_iso_to_datastore_username** (str, required)
- The vSphere vCenter or ESXi host username.
- If this variable is not set, the collection level variable `vmware_ops_username` will be used. If that variable is not set, the environment variable `VMWARE_USER` will be used. At least one of these variables must be set to use this role.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

- **upload_iso_to_datastore_password** (str, required)
- The vSphere vCenter or ESXi host password.
- If this variable is not set, the collection level variable `vmware_ops_password` will be used. If that variable is not set, the environment variable `VMWARE_PASSWORD` will be used. At least one of these variables must be set to use this role.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

- **upload_iso_to_datastore_validate_certs** (bool)
- Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted.
- If this variable is not set, the collection level variable `vmware_ops_validate_certs` will be used. If that variable is not set, the environment variable `VMWARE_VALIDATE_CERTS` will be used.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

- **upload_iso_to_datastore_port** (int or str)
- The port used to authenticate to the vSphere vCenter or ESXi host.
- If this variable is not set, the collection level variable `vmware_ops_port` will be used. If that variable is not set, the environment variable `VMWARE_PORT` will be used.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

### Proxy

- **upload_iso_to_datastore_proxy_host** (str)
- The hostname of a proxy host that should be used for all HTTPs communication by the role.
- The format is a hostname or an IP.
- If this variable is not set, the collection level variable `vmware_ops_proxy_host` will be used. If that variable is not set, the environment variable `VMWARE_PROXY_HOST` will be used.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

- **upload_iso_to_datastore_proxy_port** (str or int)
- The port of a proxy host that should be used for all HTTPs communication by the role
- If this variable is not set, the collection level variable `vmware_ops_proxy_host` will be used. If that variable is not set, the environment variable `VMWARE_PROXY_PORT` will be used.
- See the [authentication documentation](https://github.com/redhat-cop/cloud.vmware_ops/blob/main/docs/authentication.md) for examples.

### Uploading an ISO file

- **upload_iso_to_datastore_src** (str, required)
- Absolute path to the ISO file to upload.
- This parameter is case sensitive.

- **upload_iso_to_datastore_datacenter** (str, required)
- The name of the datacenter where the Datastore resides.
- This parameter is case sensitive.

- **upload_iso_to_datastore_datastore** (str, required)
- The ISO will be uploaded into this Datastore.
- Please see the examples for more usage.

- **upload_iso_to_datastore_dst** (str, required)
- The ISO file will be uploaded into this destination path within the Datastore.
- This parameter is case sensitive.

## Examples

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:

```yaml
---
- hosts: localhost
gather_facts: true

tasks:
- name: Upload ISO to Datastore
ansible.builtin.import_role:
name: cloud.vmware_ops.upload_iso_to_datastore
vars:
upload_iso_to_datastore_hostname: "test"
upload_iso_to_datastore_username: "test"
upload_iso_to_datastore_password: "test"
upload_iso_to_datastore_validate_certs: false
upload_iso_to_datastore_datacenter: "DC0"
upload_iso_to_datastore_port: "8989"
upload_iso_to_datastore_datastore: "eco-iscsi-ds1"
upload_iso_to_datastore_src: "/tmp/test.iso"
upload_iso_to_datastore_dst: "/test.iso"
```
Run the playbook:
```shell
ansible-playbook playbook.yml -e "@vars.yml"
```

## License

GNU General Public License v3.0 or later

See [LICENSE](https://github.com/ansible-collections/cloud.vmware_ops/blob/main/LICENSE) to see the full text.

## Author Information

- Ansible Cloud Content Team
9 changes: 9 additions & 0 deletions roles/upload_iso_to_datastore/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
upload_iso_to_datastore_hostname: "{{ vmware_ops_collection_hostname }}"
upload_iso_to_datastore_username: "{{ vmware_ops_collection_username }}"
upload_iso_to_datastore_password: "{{ vmware_ops_collection_password }}"
upload_iso_to_datastore_validate_certs: "{{ vmware_ops_collection_validate_certs }}"
upload_iso_to_datastore_port: "{{ vmware_ops_collection_port }}"

upload_iso_to_datastore_proxy_host: "{{ vmware_ops_collection_proxy_host }}"
upload_iso_to_datastore_proxy_port: "{{ vmware_ops_collection_proxy_port }}"
12 changes: 12 additions & 0 deletions roles/upload_iso_to_datastore/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
galaxy_info:
author: Ansible Cloud Content Team (@redhat-cop)
description: Upload an ISO file to a Datastore in vCenter
company: Red Hat, Inc.
license: GPL-3.0-or-later
min_ansible_version: "2.13"
galaxy_tags:
- infrastructure
- vmware

dependencies: []
28 changes: 28 additions & 0 deletions roles/upload_iso_to_datastore/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- name: Import Collection Level Vars
ansible.builtin.include_vars:
file: "{{ role_path }}/../../vars/main.yml"

- name: Check Mandatory Variables Are Defined
ansible.builtin.assert:
that:
- upload_iso_to_datastore_hostname is defined
- upload_iso_to_datastore_username is defined
- upload_iso_to_datastore_password is defined
- upload_iso_to_datastore_src is defined
- upload_iso_to_datastore_dst is defined
- upload_iso_to_datastore_datastore is defined
- upload_iso_to_datastore_datacenter is defined
quiet: true
fail_msg: Variable must be set when using this role.

- name: Upload local ISO file to Datastore
community.vmware.vsphere_copy:
hostname: "{{ upload_iso_to_datastore_hostname }}"
username: "{{ upload_iso_to_datastore_username }}"
password: "{{ upload_iso_to_datastore_password }}"
src: "{{ upload_iso_to_datastore_src }}"
datacenter: "{{ upload_iso_to_datastore_datacenter }}"
datastore: "{{ upload_iso_to_datastore_datastore }}"
path: "{{ upload_iso_to_datastore_dst }}"
validate_certs: "{{ upload_iso_to_datastore_validate_certs }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- hosts: localhost
gather_facts: no

tasks:
- name: Import eco-vcenter credentials
ansible.builtin.include_vars:
file: ../../integration_config.yml
tags: eco-vcenter-ci

- name: Import Upload ISO to Datastore role
ansible.builtin.import_role:
name: vmware_ops_upload_iso_to_datastore_test
tags:
- eco-vcenter-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- name: Import common vars
ansible.builtin.include_vars:
file: ../group_vars.yml

- name: Create ISO Mocks
block:
- name: Mock VCSA Binary
ansible.builtin.include_tasks: mock_vcsa_binary.yml
always:
- name: Clean Up Temp Files
ansible.builtin.file:
path: "{{ upload_iso_to_datastore_test_mock_binary_root }}"
state: absent

- name: Test ISO Upload to Datastore
block:
- name: Upload ISO to Datastore
ansible.builtin.import_role:
name: cloud.vmware_ops.upload_iso_to_datastore

- name: Attempt to recreate ISO file
community.vmware.vsphere_file:
hostname: '{{ vmware_ops_hostname }}'
username: '{{ vmware_ops_username }}'
password: '{{ vmware_ops_password }}'
datacenter: "{{ upload_iso_to_datastore_datacenter }}"
datastore: "{{ upload_iso_to_datastore_datastore }}"
path: "{{ upload_iso_to_datastore_dst }}"
state: file
validate_certs: "{{ vmware_ops_validate_certs }}"
ignore_errors: true
register: file_result

- name: Check ISO was copied to Datastore
ansible.builtin.assert:
that:
- file_result is not changed
quiet: true
fail_msg: Copy of ISO was unsuccessful

always:
- name: Clean Up Temp ISO
ansible.builtin.file:
path: "{{ upload_iso_to_datastore_src }}"
state: absent

- name: Delete ISO file from Datastore
community.vmware.vsphere_file:
hostname: "{{ vmware_ops_hostname }}"
username: "{{ vmware_ops_username }}"
password: "{{ vmware_ops_password }}"
state: absent
datacenter: "{{ upload_iso_to_datastore_datacenter }}"
datastore: "{{ upload_iso_to_datastore_datastore }}"
path: "{{ upload_iso_to_datastore_dst }}"
validate_certs: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Create Mock VCSA Deployment Binary Path
ansible.builtin.file:
path: "{{ upload_iso_to_datastore_test_mock_binary_root }}/lin64"
state: directory

- name: Create Mock VCSA ISO file
community.general.iso_create:
src_files:
- "{{ upload_iso_to_datastore_test_mock_binary_root }}"
dest_iso: "{{ upload_iso_to_datastore_src }}"
interchange_level: 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
run_on_simulator: false

upload_iso_to_datastore_datacenter: "{{ vcenter_datacenter }}"
upload_iso_to_datastore_datastore: "{{ shared_storage_01 }}"
upload_iso_to_datastore_src: "/tmp/{{ tiny_prefix }}-test.iso"
folder_dst: "/upload_iso_to_datastore"
upload_iso_to_datastore_dst: "{{ folder_dst }}/{{ tiny_prefix }}-test.iso"

upload_iso_to_datastore_test_mock_binary_root: /tmp/vcsa-cli-installer

0 comments on commit acc23b7

Please sign in to comment.