Skip to content
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

upload iso to datastore #120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Empty file.
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: []
26 changes: 26 additions & 0 deletions roles/upload_iso_to_datastore/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Import Collection Level Vars
ansible.builtin.include_vars:
file: "{{ role_path }}/../../vars/main.yml"

- name: Check Mandatory Variables Are Defined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upload_iso_to_datastore_src is also required

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_datastore 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}}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe here we can add an option to upload a file to a specific directory inside the datastore?
we can do a task before this one, that creates a folder in a specific datastore, and then upload the iso to that folder

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: '{{ upload_iso_to_datastore_hostname }}'
username: '{{ upload_iso_to_datastore_username }}'
password: '{{ upload_iso_to_datastore_password }}'
datacenter: "{{ upload_iso_to_datastore_datacenter }}"
datastore: "{{ upload_iso_to_datastore_datastore }}"
path: "{{ upload_iso_to_datastore_dst }}"
state: file
validate_certs: false
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: "{{ upload_iso_to_datastore_hostname }}"
username: "{{ upload_iso_to_datastore_username }}"
password: "{{ upload_iso_to_datastore_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,9 @@
---
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/test.iso"
upload_iso_to_datastore_dst: "/test.iso"

upload_iso_to_datastore_test_mock_binary_root: /tmp/vcsa-cli-installer