Issue with URI module in ansible1.9-1.9.6-2

Hi all,

I am on CentOS 6.7 using Ansible 1.9 and I’ve updated my version of Ansible to be ansible1.9-1.9.6-2 (retrieved from EPEL).

I have some tasks ([1]) which upload (via POST) dashboards to Grafana. Those tasks used to run just fine in the previous version of Ansible (4-2) but with the most recent release of the 1.9 branch, they fail with an error ([2]).

[1]

  • name: import the Cluster dashboards
    uri:
    url: http://127.0.0.1:3000/api/dashboards/db
    method: POST
    body: “{{ lookup(‘file’, ‘/tmp/cluster.json’) }}”
    body_format: json
    HEADER_Content-Type: “application/json”
    user: admin
    password: admin
    force_basic_auth: yes

[2]

TASK: [grafana-2-dashboards | import the Cluster dashboards] ******************
failed: [10.165.1.41] => {“failed”: true, “parsed”: false}
BECOME-SUCCESS-pjcvvpproqvedvdzjlxsjvwndajwkzee
Traceback (most recent call last):
File “/root/.ansible/tmp/ansible-tmp-1463513575.1-256930227119349/uri”, line 2106, in
main()
File “/root/.ansible/tmp/ansible-tmp-1463513575.1-256930227119349/uri”, line 415, in main
resp, content, dest = uri(module, url, dest, user, password, body, method, dict_headers, redirects, socket_timeout, validate_certs)
File “/root/.ansible/tmp/ansible-tmp-1463513575.1-256930227119349/uri”, line 311, in uri
resp, content = h.request(url, method=method, body=body, headers=headers)
File “/usr/lib/python2.6/site-packages/httplib2/init.py”, line 1605, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File “/usr/lib/python2.6/site-packages/httplib2/init.py”, line 1353, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File “/usr/lib/python2.6/site-packages/httplib2/init.py”, line 1290, in _conn_request
conn.request(method, request_uri, body, headers)
File “/usr/lib64/python2.6/httplib.py”, line 936, in request
self._send_request(method, url, body, headers)
File “/usr/lib64/python2.6/httplib.py”, line 976, in _send_request
self.send(body)
File “/usr/lib64/python2.6/httplib.py”, line 781, in send
self.sock.sendall(str)
File “”, line 1, in sendall
TypeError: sendall() argument 1 must be string or buffer, not dict
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 2
debug1: mux_client_request_session: master session id: 2

I would appreciate any pointers to help me debug this.

Thanks in advance for your help.

Guillaume.

I think uri may have changed and it might not be necessary to set the
HEADER_Content-Type
any more now that you are setting body_format: json

Also I’ve seen elsewhere that you may need to insert a space to avoid a type conversion problem.

Try changing

body: “{{ lookup(‘file’, ‘/tmp/cluster.json’) }}”

to

body: " {{ lookup(‘file’, ‘/tmp/cluster.json’) }}"

If that doesn’t work and you get past the stracktrace then I suggest trying something like wireshark to inspect what uri actually sends.

Hope this helps,

Jon

Hi Jon,

Wow, many thanks for your help, adding the space was enough to fix the issue!!!
Do you happen to know if there is a more intuitive way of preventing the type conversion ? Maybe applying a filter ?
In 1.9, I actually think the body_format option is not supported, so I have to specify the content type.
I owe you big time for your help.

Guillaume.

Hi Guillaume,

Pretty much everything I know about this issue is from the discussion on this thread: https://groups.google.com/forum/#!topic/ansible-devel/2C7pl2_kxlY

Jon