Ansible 2.8 uri module follows 302 even if follow_redirects is set to none

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?

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

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