# uri module following redirects even after follow\_redirects=no has been set

**URL:** <https://forum.ansible.com/t/uri-module-following-redirects-even-after-follow-redirects-no-has-been-set/14388>\
**Category:** Ansible Project\
**Created:** [January 20, 2014, 8:44pm UTC](https://forum.ansible.com/t/uri-module-following-redirects-even-after-follow-redirects-no-has-been-set/14388 "2014-01-20T20:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bennett\_ponder](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@bennett\_ponder](https://forum.ansible.com/u/bennett_ponder)\
**Post date:** [January 20, 2014, 8:44pm UTC](https://forum.ansible.com/t/uri-module-following-redirects-even-after-follow-redirects-no-has-been-set/14388/1 "2014-01-20T20:44:09Z")

</div>

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](http://test.site.com)” follow\_redirects=no  
delegate\_to: 127.0.0.1

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 21, 2014, 12:50am UTC](https://forum.ansible.com/t/uri-module-following-redirects-even-after-follow-redirects-no-has-been-set/14388/2 "2014-01-21T00:50:32Z")

</div>

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](https://github.com/ansible/ansible/blob/devel/library/network/uri)

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [January 23, 2014, 8:10pm UTC](https://forum.ansible.com/t/uri-module-following-redirects-even-after-follow-redirects-no-has-been-set/14388/3 "2014-01-23T20:10:34Z")

</div>

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

[https://github.com/ansible/ansible/commit/5c0daf9e0a3a58253df61e56e39333637202cd12](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

---

<div class="post-metadata">

**Author:** ![Romeo\_Theriault](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Romeo\_Theriault](https://forum.ansible.com/u/Romeo_Theriault)\
**Post date:** [January 30, 2014, 12:27am UTC](https://forum.ansible.com/t/uri-module-following-redirects-even-after-follow-redirects-no-has-been-set/14388/4 "2014-01-30T00:27:16Z")

</div>

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](https://github.com/ansible/ansible/pull/5826)

Romeo
