Instead of json.token you need to reference the variable that you registered. Such as:
authentication.json.token `json` is a key off of the registered var from the task. On Friday, January 8, 2016, Glenn Barnard <[email protected]> wrote: > 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 > > -- > 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] > <javascript:_e(%7B%7D,'cvml','ansible-project%[email protected]');> > . > To post to this group, send email to [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/15ce9f57-e79c-44bc-ad1f-0c6aa958309d%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/15ce9f57-e79c-44bc-ad1f-0c6aa958309d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Matt Martz @sivel sivel.net -- 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/CAD8N0v88rToBNw8SmG8rJOL-RprFtZ%2BRQvX7JoQbhgfcyBZr8w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
