TypeError: unhashable type despite using body-format: json in uri: task
TypeError: unhashable type despite using body-format: json in uri: task
如果我将正文添加到 uri: 任务,任务将失败并显示 "Status code was -1 and not [200]: An unknown error occurred: unhashable type"
如果我删除正文:那么 Web 服务 returns 一个错误(因为它需要正文!)但至少它到达了 web 服务!
这是任务:
- name: create new RE if RE doesn't exist
uri:
url: https://api.eu.cloud.talend.com/tmc/v1.3/runtimes/remote-engines
method: POST
headers:
Authorization: Basic {{talend_personal_access_token}}
Accept: application/json
status-code: 201
body-format: json
body:
name: "{{RE_name}}"
register: new_RE_response
when: check_response.json[0].id is undefined
这是输出:
{
"status": -1,
"exception": "Traceback (most recent call last):\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 1359, in fetch_url\n unix_socket=unix_socket)\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 1257, in open_url\n use_gssapi=use_gssapi, unix_socket=unix_socket)\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 1163, in open\n r = urllib_request.urlopen(*urlopen_args)\n File \"/usr/lib64/python2.7/urllib2.py\", line 154, in urlopen\n return opener.open(url, data, timeout)\n File \"/usr/lib64/python2.7/urllib2.py\", line 431, in open\n response = self._open(req, data)\n File \"/usr/lib64/python2.7/urllib2.py\", line 449, in _open\n '_open', req)\n File \"/usr/lib64/python2.7/urllib2.py\", line 409, in _call_chain\n result = func(*args)\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 356, in https_open\n return self.do_open(CustomHTTPSConnection, req)\n File \"/usr/lib64/python2.7/urllib2.py\", line 1211, in do_open\n h.request(req.get_method(), req.get_selector(), req.data, headers)\n File \"/usr/lib64/python2.7/httplib.py\", line 1056, in request\n self._send_request(method, url, body, headers)\n File \"/usr/lib64/python2.7/httplib.py\", line 1090, in _send_request\n self.endheaders(body)\n File \"/usr/lib64/python2.7/httplib.py\", line 1052, in endheaders\n self._send_output(message_body)\n File \"/usr/lib64/python2.7/httplib.py\", line 894, in _send_output\n self.send(message_body)\n File \"/usr/lib64/python2.7/httplib.py\", line 866, in send\n self.sock.sendall(data)\n File \"/usr/lib64/python2.7/ssl.py\", line 744, in sendall\n v = self.send(data[count:])\nTypeError: unhashable type\n",
"url": "https://api.eu.cloud.talend.com/tmc/v1.3/runtimes/remote-engines",
"changed": false,
"elapsed": 1,
"content": "",
"invocation": {
"module_args": {
"directory_mode": null,
"force": false,
"remote_src": null,
"status_code": [
200
],
"follow": false,
"owner": null,
"body_format": "raw",
"body-format": "json",
"client_key": null,
"group": null,
"use_proxy": true,
"headers": {
"Accept": "application/json",
"Authorization": "Basic <censored>"
},
"unsafe_writes": null,
"setype": null,
"content": null,
"serole": null,
"follow_redirects": "safe",
"return_content": false,
"client_cert": null,
"body": {
"name": "RHEL_X.X.X.X_AZGLGBNEVTA30_PRODUCTION_C4E"
},
"timeout": 30,
"src": null,
"dest": null,
"selevel": null,
"force_basic_auth": true,
"removes": null,
"http_agent": "ansible-httpget",
"regexp": null,
"status-code": 201,
"url_password": null,
"url": "https://api.eu.cloud.talend.com/tmc/v1.3/runtimes/remote-engines",
"validate_certs": true,
"seuser": null,
"method": "POST",
"creates": null,
"unix_socket": null,
"delimiter": null,
"mode": null,
"url_username": null,
"attributes": null,
"backup": null
}
},
"redirected": false,
"msg": "Status code was -1 and not [200]: An unknown error occurred: unhashable type",
"_ansible_no_log": false
}
这是 Ansible 版本:
ansible --version
ansible 2.9.4
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/jason_ho/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Jun 11 2019, 14:33:56) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
这是 运行 通过 AWX 9.1.1
是错误还是我做错了什么?
首先,您正在使用状态代码 201 并期望状态代码为 200 成功。如果您期望 200 成功响应,请删除状态代码。
其次,如果您要发送 POST 请求,请使用 return_content: true
。
了解更多信息。检查 https://docs.ansible.com/ansible/latest/modules/uri_module.html#uri-interacts-with-webservices
您的语法不正确。正确的变量是 status_code
,而不是 status-code
。
("underline" 而不是 "dash":https://docs.ansible.com/ansible/latest/modules/uri_module.html)
如果我将正文添加到 uri: 任务,任务将失败并显示 "Status code was -1 and not [200]: An unknown error occurred: unhashable type"
如果我删除正文:那么 Web 服务 returns 一个错误(因为它需要正文!)但至少它到达了 web 服务!
这是任务:
- name: create new RE if RE doesn't exist
uri:
url: https://api.eu.cloud.talend.com/tmc/v1.3/runtimes/remote-engines
method: POST
headers:
Authorization: Basic {{talend_personal_access_token}}
Accept: application/json
status-code: 201
body-format: json
body:
name: "{{RE_name}}"
register: new_RE_response
when: check_response.json[0].id is undefined
这是输出:
{
"status": -1,
"exception": "Traceback (most recent call last):\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 1359, in fetch_url\n unix_socket=unix_socket)\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 1257, in open_url\n use_gssapi=use_gssapi, unix_socket=unix_socket)\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 1163, in open\n r = urllib_request.urlopen(*urlopen_args)\n File \"/usr/lib64/python2.7/urllib2.py\", line 154, in urlopen\n return opener.open(url, data, timeout)\n File \"/usr/lib64/python2.7/urllib2.py\", line 431, in open\n response = self._open(req, data)\n File \"/usr/lib64/python2.7/urllib2.py\", line 449, in _open\n '_open', req)\n File \"/usr/lib64/python2.7/urllib2.py\", line 409, in _call_chain\n result = func(*args)\n File \"/tmp/ansible_uri_payload_nEptqB/ansible_uri_payload.zip/ansible/module_utils/urls.py\", line 356, in https_open\n return self.do_open(CustomHTTPSConnection, req)\n File \"/usr/lib64/python2.7/urllib2.py\", line 1211, in do_open\n h.request(req.get_method(), req.get_selector(), req.data, headers)\n File \"/usr/lib64/python2.7/httplib.py\", line 1056, in request\n self._send_request(method, url, body, headers)\n File \"/usr/lib64/python2.7/httplib.py\", line 1090, in _send_request\n self.endheaders(body)\n File \"/usr/lib64/python2.7/httplib.py\", line 1052, in endheaders\n self._send_output(message_body)\n File \"/usr/lib64/python2.7/httplib.py\", line 894, in _send_output\n self.send(message_body)\n File \"/usr/lib64/python2.7/httplib.py\", line 866, in send\n self.sock.sendall(data)\n File \"/usr/lib64/python2.7/ssl.py\", line 744, in sendall\n v = self.send(data[count:])\nTypeError: unhashable type\n",
"url": "https://api.eu.cloud.talend.com/tmc/v1.3/runtimes/remote-engines",
"changed": false,
"elapsed": 1,
"content": "",
"invocation": {
"module_args": {
"directory_mode": null,
"force": false,
"remote_src": null,
"status_code": [
200
],
"follow": false,
"owner": null,
"body_format": "raw",
"body-format": "json",
"client_key": null,
"group": null,
"use_proxy": true,
"headers": {
"Accept": "application/json",
"Authorization": "Basic <censored>"
},
"unsafe_writes": null,
"setype": null,
"content": null,
"serole": null,
"follow_redirects": "safe",
"return_content": false,
"client_cert": null,
"body": {
"name": "RHEL_X.X.X.X_AZGLGBNEVTA30_PRODUCTION_C4E"
},
"timeout": 30,
"src": null,
"dest": null,
"selevel": null,
"force_basic_auth": true,
"removes": null,
"http_agent": "ansible-httpget",
"regexp": null,
"status-code": 201,
"url_password": null,
"url": "https://api.eu.cloud.talend.com/tmc/v1.3/runtimes/remote-engines",
"validate_certs": true,
"seuser": null,
"method": "POST",
"creates": null,
"unix_socket": null,
"delimiter": null,
"mode": null,
"url_username": null,
"attributes": null,
"backup": null
}
},
"redirected": false,
"msg": "Status code was -1 and not [200]: An unknown error occurred: unhashable type",
"_ansible_no_log": false
}
这是 Ansible 版本:
ansible --version
ansible 2.9.4
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/jason_ho/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Jun 11 2019, 14:33:56) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
这是 运行 通过 AWX 9.1.1
是错误还是我做错了什么?
首先,您正在使用状态代码 201 并期望状态代码为 200 成功。如果您期望 200 成功响应,请删除状态代码。
其次,如果您要发送 POST 请求,请使用 return_content: true
。
了解更多信息。检查 https://docs.ansible.com/ansible/latest/modules/uri_module.html#uri-interacts-with-webservices
您的语法不正确。正确的变量是 status_code
,而不是 status-code
。
("underline" 而不是 "dash":https://docs.ansible.com/ansible/latest/modules/uri_module.html)