Moving Template or OVA to Datastore using vCenter API

26 views Asked by At

As part of an Ansible Installation Process, we need to import some ISO, OVA files or template files up to a datastore so we can use them in the installation process. We have an existing token for the API access already, so we we would like to use that authentication to move the file up. To avoid dependencies, we are only using Ansible URI calls to the vCenter API, and hope we can continue that method.

  • Is there a way to copy an OVA or VMDK file from a local Linux host (currently Ubuntu 22.04) to the an ESXi host through the vCenter API?
  • We have a list of hosts in the cluster already from the API. If we could upload a file using the authentication we already have through vCenter that would be preferred. We are trying to avoid having to have two sets of authentication to complete the install.

We see where govc and PowerCli are capable of uploading files to datastores, and we see were the GUI can upload OVAs and other files through the vCenter without requiring root authentication, but we have not been able to find an API call that works to upload the files we need. I now we could do this with ssh or govc, but we are trying to avoid multiple authentication methods (ssh / root access to hosts as an example) and would like to limit the dependencies on other tools where ever possible. Can this be done through the API? I see reference that SOAP might be the way to do this, but I don't see any examples.

So far we have tried:

  - name: Upload File
    uri:
      url:  "https://{{ vcenter_hostname }}/folder/{{ upload_datastore }}/Some-test-file.iso"
      method: PUT
      src: ISOs/debian/11/debian-11.9.0-amd64-DVD-1.iso
      force_basic_auth: yes 
      validate_certs: no
      headers:
        Cookie: "{{ auth_cookie.set_cookie }}"

We have also tried to write to an ESXi host using the same token we got from vCenter during the auth process

  - name: Upload File
    uri:
      url:  "https://{{ esxi_hostname }}/folder/{{ upload_datastore }}/Some-test-file.iso"
      method: PUT
      src: ISOs/debian/11/debian-11.9.0-amd64-DVD-1.iso
      force_basic_auth: yes 
      validate_certs: no
      headers:
        Cookie: "{{ auth_cookie.set_cookie }}"

Goal is for the ISO to get created in the datastore. I just need to understand the API call. I know other tools can do this, but this question is specifically about the calls to the vCenter server to complete this action.

0

There are 0 answers