ansible-collections / vmware.vmware_rest

Ansible Collection for VMWare (REST modules)
https://ansible-collections.github.io/vmware.vmware_rest/
GNU General Public License v3.0
131 stars 64 forks source link

Error: Attempt to decode JSON with unexpected mimetype #372

Open ntgiangictu opened 1 year ago

ntgiangictu commented 1 year ago
SUMMARY

Ansible Automation Private Hub is using vmware_rest collection v1.0.1 VMware vCenter is using version 6.7U3 When it run by module vmware.vmware_rest.vcenter_vm_info, the error return

ContentTypeError(\naiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html;charset=iso-8859-1', url=URL('https://X.X.X.X/api/vcenter/vm?names=XXX')

It's seem like the issue on the url https://github.com/ansible-collections/vmware.vmware_rest/issues/257

ISSUE TYPE
COMPONENT NAME

vmware.vmware_rest.vcenter_vm_info

ANSIBLE VERSION

ansible [core 2.13.3] config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.9/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible python version = 3.9.13 (main, Nov 9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)] jinja version = 3.1.2 libyaml = True

COLLECTION VERSION

vmware.vmware_rest v1.0.1 cloud.common v2.1.2

CONFIGURATION
OS / ENVIRONMENT

Red Hat 8.7

STEPS TO REPRODUCE

Playbook:

---
- name: This playbook to get VM info
  hosts: localhost
  gather_facts: false
  collections:
  - vmware.vmware_rest

  tasks:
    - name: Include Secret Environment Items
      include_vars:
        file: secrets.yml
        name: secret

    - name: Collect information about VM
      vmware.vmware_rest.vcenter_vm_info:
        vcenter_hostname: "{{ secret.vcenter }}"
        vcenter_username: "{{ secret.username }}"
        vcenter_password: "{{ secret.password }}"
        vcenter_validate_certs: no
        filter_names:
        - XXX
EXPECTED RESULTS

The result of VM

ACTUAL RESULTS

{ "msg": [ " File \"/usr/lib64/python3.9/runpy.py\", line 197, in _run_module_as_main\n return _run_code(code, main_globals, None,\n", " File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n", " File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py\", line 382, in \n", " File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py\", line 359, in start\n", " File \"/usr/lib64/python3.9/asyncio/base_events.py\", line 596, in run_forever\n self._run_once()\n", " File \"/usr/lib64/python3.9/asyncio/base_events.py\", line 1890, in _run_once\n handle._run()\n", " File \"/usr/lib64/python3.9/asyncio/events.py\", line 80, in _run\n self._context.run(self._callback, *self._args)\n", " File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py\", line 330, in handle\n", " File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py\", line 295, in run_as_module\n", "Traceback (most recent call last):\n File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/cloud/common/plugins/module_utils/turbo/server.py\", line 199, in run\n File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_info.py\", line 464, in main\n result = await entry_point(module, session)\n File \"/tmp/ansible_vmware.vmware_rest.vcenter_vm_info_payload_f81avl5x/ansible_vmware.vmware_rest.vcenter_vm_info_payload.zip/ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_info.py\", line 486, in entry_point\n _json = await resp.json()\n File \"/usr/local/lib64/python3.9/site-packages/aiohttp/client_reqrep.py\", line 1097, in json\n raise ContentTypeError(\naiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html;charset=iso-8859-1', url=URL('https://X.X.X.X/api/vcenter/vm?names=XXX')\n" ], "invocation": { "module_args": { "vcenter_hostname": "XXX", "vcenter_username": "XXX", "vcenter_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "vcenter_validate_certs": false, "filter_names": [ "XXX" ], "names": [ "XXX" ], "vcenter_rest_log_file": null, "session_timeout": null, "clusters": null, "datacenters": null, "folders": null, "hosts": null, "power_states": null, "resource_pools": null, "vm": null, "vms": null } }, "_ansible_no_log": null, "changed": false }

Haargrad commented 1 year ago

I have the same problem, any thoughts on a solution?

ntgiangictu commented 1 year ago

I have the same problem, any thoughts on a solution?

By the way I found problem by vmware collection is not install or the directory of collection is not configured.

Haargrad commented 1 year ago

I have the same problem, any thoughts on a solution?

By the way I found problem by vmware collection is not install or the directory of collection is not configured.

.ansible/collections/ansible_collections Collection Version


cloud.common 2.1.2 community.vmware 3.3.0 netbox.netbox 3.10.0 vmware.vmware_rest 2.2.0

pip list Package Version


aiohttp 3.8.3 aiosignal 1.3.1 ansible 7.1.0 .......

i install all what is needed

ntgiangictu commented 1 year ago

First time, you need to be sure that the collections are installed on position correctly. In my environment, I found it in /var/lib/awx/.ansible.... Or, you can try to use command find for check the location of collections. Ansible Automation is using podman under container.

Haargrad commented 1 year ago

all my collections are in my home directory, and i use netbox for example, it work 100% fine And now i started using community.vmware, and this collection works great

fs30000 commented 1 year ago

Still happening.