0

Using ansibles uri module, how would you figure out if the url is being created correctly? It seems to me like its dropping something or not adding something.

-name: Get messages from xyz
 uri:
    url: https://api.domain.com/random/message
    method: GET
    body_format: form-urlencoded
    body:
    -[from, 8484924]
register: messagesxyz

Expectation is that the uri module url encodes this data as https://api.domain.com/random/message/?from=8484924 . What appears to be happening based off a guess is it is not adding anything. Anyway to see what url it is generating?

I have tried various formats for the body as well

body:
  from: 8484924

body:
  'from=8484924'
james
  • 157
  • 1
  • 2
  • 11
  • The body of a request and its URI are two different things. What you want to do is `url: https://api.domain.com/random/message?from= 8484924 `. On top of that, the snippet of code you are providing is all wrong (you are at least missing a module, I guess the `uri` one, in the YAML provided here). Please have a look at [ask] – β.εηοιτ.βε May 14 '21 at 18:54
  • Yea my bad on forgetting the module, the machine I am developing on and the machine that this is posted from are different. I have updated the code. When using the form-urlencoded does that not add it to the url in urlencoded form? – james May 14 '21 at 19:50
  • Directly from a helpful person on reddit... All right. According to the docs you can get the URL used in the request by accessing the url key in the return dict. In your case you should be able to just print the registered messagexyz variable with the debug module and it’ll be there along the other return values. source: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html (Scroll to the bottom) Thanks @hgevoyio Technically this resolves the question, however the uri module does not appear to work as expected and does not append to the url. – james May 14 '21 at 19:53
  • It works as expected. You are mixing body and header. The URL is part of the header, the body is something else. Related: https://stackoverflow.com/questions/22034144/what-does-it-mean-http-request-body – β.εηοιτ.βε May 14 '21 at 19:56
  • I think I understand what your saying, however the documentation says it will transform the body to headers when using url-encode for body-form https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html#parameter-body_format – james May 14 '21 at 20:01
  • *As of 2.3 it is possible to override the `Content-Type` header*. The `Content-Type` one, not any random GET parameter header. – β.εηοιτ.βε May 14 '21 at 20:04
  • Clearly I am not understanding the difference, ill look some things up and see where this goes. Overall this seems like a very simple thing to do that is becoming a mess. Appreciate your time! – james May 14 '21 at 20:09

0 Answers0