From 098333b2ecad3f99deb95763f2db1530915620c5 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 7 Mar 2016 15:35:20 -0600 Subject: [PATCH] Fix redirects for get_url * fetch_url shouldn't both accept follow_redirects and support follow_redircts via module.params * Default follow_redirects for open_url should be 'urllib2' * Add redirect test for get_url --- lib/ansible/module_utils/urls.py | 8 +++----- test/integration/roles/test_get_url/tasks/main.yml | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 0d0965e3ab..51779dc4e1 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -676,7 +676,7 @@ def maybe_add_ssl_handler(url, validate_certs): def open_url(url, data=None, headers=None, method=None, use_proxy=True, force=False, last_mod_time=None, timeout=10, validate_certs=True, url_username=None, url_password=None, http_agent=None, - force_basic_auth=False, follow_redirects=False): + force_basic_auth=False, follow_redirects='urllib2'): ''' Fetches a file from an HTTP/FTP server using urllib2 ''' @@ -809,8 +809,7 @@ def url_argument_spec(): ) def fetch_url(module, url, data=None, headers=None, method=None, - use_proxy=True, force=False, last_mod_time=None, timeout=10, - follow_redirects=False): + use_proxy=True, force=False, last_mod_time=None, timeout=10): ''' Fetches a file from an HTTP/FTP server using urllib2. Requires the module environment ''' @@ -828,8 +827,7 @@ def fetch_url(module, url, data=None, headers=None, method=None, http_agent = module.params.get('http_agent', None) force_basic_auth = module.params.get('force_basic_auth', '') - if not follow_redirects: - follow_redirects = module.params.get('follow_redirects', False) + follow_redirects = module.params.get('follow_redirects', 'urllib2') r = None info = dict(url=url) diff --git a/test/integration/roles/test_get_url/tasks/main.yml b/test/integration/roles/test_get_url/tasks/main.yml index 9ed0549ec4..46d9ee275d 100644 --- a/test/integration/roles/test_get_url/tasks/main.yml +++ b/test/integration/roles/test_get_url/tasks/main.yml @@ -145,3 +145,8 @@ - 'get_url_result["failed"]' when: "{{ not python_has_ssl_context }}" # End hacky SNI test section + +- name: Test get_url with redirect + get_url: + url: 'http://httpbin.org/redirect/6' + dest: "{{ output_dir }}/redirect.json"