Search code examples
ansiblevsphere

Unable to deploying the vCenter Server Appliance OVF with Ansible


I would like to make a playbook for deploying Vcenter from an OVF file but I have an error. I've tried to find out the root cause, but, it didn't work out. Here you can see my playbook :

- hosts: localhost
  connection: local
  become: yes
  gather_facts: false
  ignore_errors: true
  collections:
    - community.vmware
  pre_tasks:
    - include_vars: vars.yml
  tasks:
      - name: deploy ovf
        vmware_deploy_ovf:
          hostname: "{{ hostname }}"
          username: "{{ username }}"
          password: "{{ password }}"
          validate_certs: "{{ validate_certs }}"
          datacenter: "{{ datacenter }}"
          name: "{{ vm_name }}"
          ovf: "{{ ovf_path }}"
          cluster: "{{ cluster }}"
          wait_for_ip_address: true
          inject_ovf_env: false
          power_on: no
          datastore: "{{ datastore }}"
          networks: "{u'Management Network':u'Management Network'}"
          disk_provisioning: thin
        delegate_to: localhost

However, I got the error message like this

>      The full traceback is:
>       File "/tmp/ansible_vmware_deploy_ovf_payload_l85kfuc6/ansible_vmware_deploy_ovf_payload.zip/ansible_collections/c
> ommunity/vmware/plugins/modules/vmware_deploy_ovf.py", line 319, in
> run
>       File "/tmp/ansible_vmware_deploy_ovf_payload_l85kfuc6/ansible_vmware_deploy_ovf_payload.zip/ansible_collections/c
> ommunity/vmware/plugins/modules/vmware_deploy_ovf.py", line 307, in
> _open_url
>       File "/tmp/ansible_vmware_deploy_ovf_payload_l85kfuc6/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/
> urls.py", line 1575, in open_url
>         return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy,
>       File "/tmp/ansible_vmware_deploy_ovf_payload_l85kfuc6/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/
> urls.py", line 1486, in open
>         return urllib_request.urlopen(request, None, timeout)
>       File "/usr/local/lib/python3.10/urllib/request.py", line 216, in urlopen
>         return opener.open(url, data, timeout)
>       File "/usr/local/lib/python3.10/urllib/request.py", line 519, in open
>         response = self._open(req, data)
>       File "/usr/local/lib/python3.10/urllib/request.py", line 536, in _open
>         result = self._call_chain(self.handle_open, protocol, protocol +
>       File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain
>         result = func(*args)
>       File "/tmp/ansible_vmware_deploy_ovf_payload_l85kfuc6/ansible_vmware_deploy_ovf_payload.zip/ansible/module_utils/
> urls.py", line 588, in https_open
>         return self.do_open(self._build_https_connection, req)
>       File "/usr/local/lib/python3.10/urllib/request.py", line 1351, in do_open
>         raise URLError(err)
>     fatal: [localhost]: FAILED! => {
>         "changed": false,
>         "invocation": {
>             "module_args": {
>                 "allow_duplicates": true,
>                 "cluster": "****",
>                 "datacenter": "*****",
>                 "datastore": "*****",
>                 "deployment_option": null,
>                 "disk_provisioning": "thin",
>                 "esxi_hostname": null,
>                 "fail_on_spec_warnings": false,
>                 "folder": null,
>                 "hostname": "********",
>                 "inject_ovf_env": false,
>                 "name": "vm-test",
>                 "networks": {
>                     "Management Network": "Management Network"
>                 },
>                 "ovf": "/path/CentOS7.ovf",
>                 "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
>                 "port": 443,
>                 "power_on": false,
>                 "properties": null,
>                 "proxy_host": null,
>                 "proxy_port": null,
>                 "resource_pool": "*******",
>                 "username": "*******",
>                 "validate_certs": false,
>                 "wait": true,
>                 "wait_for_ip_address": true
>             }
>         },
>         "msg": "<urlopen error [Errno -2] Name or service not known>"
>     }

Do you have any idea of the origin of the error please ? Thank you for your time.


Solution

  • Try on your ansible control host (or Tower/AWX) if you can resolve the names of all esxi hosts of your vmware cluster.

    The vmware_deploy_ovf module gets an url from vcenter to upload the vmdk file. That urls points to an esxi host instead of the vcenter.

    To debug this error we inserted here: https://github.com/ansible-collections/community.vmware/blob/main/plugins/modules/vmware_deploy_ovf.py#L569 the following line: self.module.warn('URL: %s' % to_native(device_upload_url))

    It should look like this:

                        self.module.fail_json(
                        msg='Failed to find VMDK file at %s' % vmdk
                    )
            self.module.warn('URL: %s' % to_native(device_upload_url))
            uploaders.append(
                VMDKUploader(
    

    The above github link points to the newset version of the vmware collection. But it should work older ones as well.

    This will output the url to where ansible wants to upload the vmdk file. So you can check if this url is reachable from your ansible control host.