Am using a current copy of Ansible and am in learning stage by writing 
playbooks that call Ansible's API's via the uri module. Am getting an error 
from the included yml that is trying to authenticate the user. Note that 
it's working fine when I put the task into the main yml. The error is a 
stack trace (below) followed with

   TypeError: unhashable type

Here's the main yml:

--- 
- name: Connect to Ansible API
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
  - include: authenticate.yml
      url="10.0.0.4"
      username="<username>"
      password="<password"

  - debug: msg='{{ authentication.json }}'

  - uri: 
      url:  https://10.0.0.4/api/v1/users/
      method: GET
      HEADER_Authorization: TOKEN {{ authentication.json.token }} 
      validate_certs: no
      return_content: yes


Here's the included yml:

---

  - debug: msg="Connecting to Ansible host with {{ username }}/{{ password 
}}"

  - name: Connect to ansible with creds provided
    uri: 
      url: https://{{ url }}/api/v1/authtoken/
      method: POST
      HEADER_Content-Type: application/json  
      body: '{ "username" : "{{ username }}", "password" : "{{ password }}" 
}'
      validate_certs: no
      return_content: yes
    register: authentication


The stack trace is:

TASK: [Connect to ansible with creds provided] 
********************************
failed: [localhost] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File 
"/home/gbarnard/.ansible/tmp/ansible-tmp-1452538099.69-278641758230235/uri", 
line 2081, in <module>
    main()
  File 
"/home/gbarnard/.ansible/tmp/ansible-tmp-1452538099.69-278641758230235/uri", 
line 416, in main
    resp, content, dest = uri(module, url, dest, user, password, body, 
method, dict_headers, redirects, socket_timeut, validate_certs)
  File 
"/home/gbarnard/.ansible/tmp/ansible-tmp-1452538099.69-278641758230235/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 1605, 
in request
    (response, content) = self._request(conn, authority, uri, request_uri, 
method, body, headers, redirections, cacekey)
  File "/usr/lib/python2.7/site-packages/httplib2/__init__.py", line 1353, 
in _request
    (response, content) = self._conn_request(conn, request_uri, method, 
body, headers)
  File "/usr/lib/python2.7/site-packages/httplib2/__init__.py", line 1290, 
in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 979, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python2.7/httplib.py", line 1013, in _send_request
    self.endheaders(body)
  File "/usr/lib64/python2.7/httplib.py", line 975, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 839, in _send_output
    self.send(message_body)
  File "/usr/lib64/python2.7/httplib.py", line 811, in send
    self.sock.sendall(data)
  File "/usr/lib64/python2.7/ssl.py", line 723, in sendall
    v = self.send(data[count:])
TypeError: unhashable type


FATAL: all hosts have already failed -- aborting

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d122348c-656e-45c5-a192-79b2663378ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to