We’re evaluating Ansible and learning how to use it. I’m trying to using Ansible to call the Ansible api’s. I have an issue with the uri module in trying to reference the response from the authtoken API to use in subsequent requests. Per the docs, the return_content option is supposed to put the json response in the dictionary with the name json. I’m ASSUMING the dictionary is the repository for variables. So, when these tasks run, the second one throws an error saying that the json varaible does not exist.
Can someone tell me how I can reference the response as a variable?
The tasks I wrote is:
-
uri:
url: https://10.0.0.4/api/v1/authtoken/
method: POST
HEADER_Content-Type: application/json
body: ‘{ “username” : “myusername”, “password” : “mypassword” }’
validate_certs: no
return_content: yes
register: authentication -
uri:
url: https://10.0.0.4/api/v1/users/
method: GET
HEADER_Authorization: TOKEN {{ json.token }}
validate_certs: no
return_content: yes