uri module following redirects even after follow_redirects=no has been set

Here’s my ansible version:

ansible --version
ansible 1.4.4

I’m trying to get ansible to submit an http request for specific a url, and verify it gets a 301. It does not need to follow the location header and make the next http request.

I figured that follow_redirects=no would solve this for me, however I see ansible make the initial http request, receive a 301, then make the next http request and get a 200 back. It then fails because I’ve said status_code=301, it must only care about the second http request it made.

This is in my task:

  • name: Make sure the HTTP Request gets a 301 redirect
    action: uri url=http://{{ inventory_hostname }}.test.com/img/site.png status_code=301 HEADER_Host=“test.site.com” follow_redirects=no
    delegate_to: 127.0.0.1

Any help would be appreciated.

Sounds like this should be filed as a bug to me.

If you are interested in poking around here and taking a look at things, here’s the source: https://github.com/ansible/ansible/blob/devel/library/network/uri

Indeed, this looks like a bug. It looks like this pull request may
have introduced it:

https://github.com/ansible/ansible/commit/5c0daf9e0a3a58253df61e56e39333637202cd12

since it looks like it's unconditionally setting 'follow_redirects' to
true. Not sure what the logic is/was here.

I'll file a bug on this and ping the author of the pull request.

Romeo

Hi Bennett, It was indeed a bug in the uri module. I've sent in a pull
request which fixes the issue.

https://github.com/ansible/ansible/pull/5826

Romeo