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

39 views
Skip to first unread message

Sam

unread,
Jun 6, 2019, 10:50:28 AM6/6/19
to Ansible Project
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?

Matt Martz

unread,
Jun 6, 2019, 11:08:38 AM6/6/19
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/10ec1717-6606-4dec-a19f-8cbdf5a68174%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Sam

unread,
Jun 6, 2019, 11:52:22 AM6/6/19
to Ansible Project
phew, thanks Matt! That worked! I would have never guessed dest would affect redirects!
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages