Sending json to webservice not working

53 views
Skip to first unread message

thecodeassassin

unread,
Sep 24, 2015, 10:17:48 AM9/24/15
to Ansible Project
hey all,

I have the following variables:

vars:
tutum_tags:
- { "name": "web" }
- { "name": "redis" }
- { "name": "memcached" }

And the following task:

- name: Main | Parsing tutum tags
set_fact:
tutum_tags_json: "{{ tutum_tags|to_json }}"

- name: Debug supplied tags
debug: msg="Set supplied tags - {{ tutum_tags_json }}"

- name: Main | Adding tags to new tutum agent
uri:
url: "{{ tutum_host ~ ' api/v1/node/' ~ tutum_agent_uuid ~ '/' }}"
method: PATCH
HEADER_Authorization: "{{ tutum_api_header }}"
HEADER_Content-Type: "application/json"
status_code: 201
body: "{{ tutum_tags_json }}"

However it's giving me this wonderful error:

TASK: [tutum-ansible-role | Main | Adding tags to new tutum agent] ************ 
failed: [default] => {"failed": true, "parsed": false}
BECOME-SUCCESS-hwnszlbrjxnztbchtlvunxntgeiksvtf
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1443101724.76-64237699457979/uri", line 2081, in <module>
    main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1443101724.76-64237699457979/uri", line 416, in main
    resp, content, dest = uri(module, url, dest, user, password, body, method, dict_headers, redirects, socket_timeout, validate_certs)
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1443101724.76-64237699457979/uri", line 312, in uri
    resp, content = h.request(url, method=method, body=body, headers=headers)     
  File "/usr/lib/python2.7/site-packages/httplib2/__init__.py", line 1608, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/python2.7/site-packages/httplib2/__init__.py", line 1350, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python2.7/site-packages/httplib2/__init__.py", line 1273, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 973, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 1007, in _send_request
    self.endheaders(body)
  File "/usr/lib64/python2.7/httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 833, in _send_output
    self.send(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 805, in send
    self.sock.sendall(data)
  File "/usr/lib64/python2.7/ssl.py", line 229, in sendall
    v = self.send(data[count:])
  File "/usr/lib64/python2.7/ssl.py", line 198, in send
    v = self._sslobj.write(data)
TypeError: must be string or buffer, not list
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/stephen/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
Shared connection to 127.0.0.1 closed.


What's weird about it is that i'm actually sending a json string and NOT a list. I cannot use body_format since we are using Ansible 1.9.3 and not 2.x.

Does anybody know how i can fix this?


Reply all
Reply to author
Forward
0 new messages