# Ansible 2.8 uri module follows 302 even if follow\_redirects is set to none

**URL:** <https://forum.ansible.com/t/ansible-2-8-uri-module-follows-302-even-if-follow-redirects-is-set-to-none/30504>\
**Category:** Ansible Project\
**Created:** [June 6, 2019, 2:50pm UTC](https://forum.ansible.com/t/ansible-2-8-uri-module-follows-302-even-if-follow-redirects-is-set-to-none/30504 "2019-06-06T14:50:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam5](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@Sam5](https://forum.ansible.com/u/Sam5)\
**Post date:** [June 6, 2019, 2:50pm UTC](https://forum.ansible.com/t/ansible-2-8-uri-module-follows-302-even-if-follow-redirects-is-set-to-none/30504/1 "2019-06-06T14:50:28Z")

</div>

ansible 2.8.0

Running uri module as

uri:  
dest: .  
url: https://{{ hostvars[inventory\_hostname].ansible\_host }}:{{ apache.port }}/context-root/some-context  
validate\_certs: false  
return\_content: true  
follow\_redirects: none  
status\_code:

- 302  
register: page  
changed\_when: false  
delegate\_to: localhost

This results in a 302 with the Location header set to a “relative” url. Ansible follows the 302, ignoring the follow\_redirects setting, and fails on the relative URL with the message

“msg”: “unknown url type: /cas/login?service=something”

The full traceback is:  
WARNING: The below traceback may _not_ be related to the actual failure.  
File “/tmp/ansible\_uri\_payload\_\_lMgyr/ansible\_uri\_payload.zip/ansible/module\_utils/urls.py”, line 1353, in fetch\_url  
unix\_socket=unix\_socket)  
File “/tmp/ansible\_uri\_payload\_\_lMgyr/ansible\_uri\_payload.zip/ansible/module\_utils/urls.py”, line 1251, in open\_url  
use\_gssapi=use\_gssapi, unix\_socket=unix\_socket)  
File “/tmp/ansible\_uri\_payload\_\_lMgyr/ansible\_uri\_payload.zip/ansible/module\_utils/urls.py”, line 1157, in open  
r = urllib\_request.urlopen(\*urlopen\_args)  
File “/usr/lib64/python2.7/urllib2.py”, line 154, in urlopen  
return opener.open(url, data, timeout)  
File “/usr/lib64/python2.7/urllib2.py”, line 423, in open  
protocol = req.get\_type()  
File “/usr/lib64/python2.7/urllib2.py”, line 285, in get\_type  
raise ValueError, “unknown url type: %s” % self.\_\_original

1. Why is Ansible ignoring the follow\_redirects setting
2. Can Ansible follow relative URLs on 302?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 6, 2019, 3:07pm UTC](https://forum.ansible.com/t/ansible-2-8-uri-module-follows-302-even-if-follow-redirects-is-set-to-none/30504/2 "2019-06-06T15:07:43Z")

</div>

The issue seems to be with your use of `dest: .`

If you use something more explicit, like `dest: "{{ playbook_dir }}"` then it will not happen.

I am working on some changes that should hopefully at some future time address the issue you are experiencing: [https://github.com/ansible/ansible/pull/50771](https://github.com/ansible/ansible/pull/50771)

---

<div class="post-metadata">

**Author:** ![Sam5](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@Sam5](https://forum.ansible.com/u/Sam5)\
**Post date:** [June 6, 2019, 3:52pm UTC](https://forum.ansible.com/t/ansible-2-8-uri-module-follows-302-even-if-follow-redirects-is-set-to-none/30504/3 "2019-06-06T15:52:22Z")

</div>

phew, thanks Matt! That worked! I would have never guessed dest would affect redirects!
