URI Module "return_content" not working per the docs

211 views
Skip to first unread message

Glenn Barnard

unread,
Jan 8, 2016, 10:31:26 AM1/8/16
to Ansible Project
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: 
      method: POST
      HEADER_Content-Type: application/json  
      body: '{ "username" : "myusername", "password" : "mypassword" }'
      validate_certs: no
      return_content: yes
      register: authentication
  
  - uri: 
      method: GET
      HEADER_Authorization: TOKEN {{ json.token }} 
      validate_certs: no
      return_content: yes

Matt Martz

unread,
Jan 8, 2016, 10:35:26 AM1/8/16
to ansible...@googlegroups.com
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.
--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/15ce9f57-e79c-44bc-ad1f-0c6aa958309d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Glenn Barnard

unread,
Jan 8, 2016, 12:58:41 PM1/8/16
to Ansible Project
Thanks Matt....A sivel star to you!


On Friday, January 8, 2016 at 10:35:26 AM UTC-5, Matt Martz wrote:
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 <barnar...@gmail.com> 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: 
      method: POST
      HEADER_Content-Type: application/json  
      body: '{ "username" : "myusername", "password" : "mypassword" }'
      validate_certs: no
      return_content: yes
      register: authentication
  
  - uri: 
      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 ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages