diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 55269210d77..0c00fe87be9 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -887,8 +887,7 @@ def fetch_url(module, url, data=None, headers=None, method=None, url_password=password, http_agent=http_agent, force_basic_auth=force_basic_auth, follow_redirects=follow_redirects) info.update(r.info()) - info['url'] = r.geturl() # The URL goes in too, because of redirects. - info.update(dict(msg="OK (%s bytes)" % r.headers.get('Content-Length', 'unknown'), status=200)) + info.update(dict(msg="OK (%s bytes)" % r.headers.get('Content-Length', 'unknown'), url=r.geturl(), status=r.getcode())) except NoSSLError, e: distribution = get_distribution() if distribution is not None and distribution.lower() == 'redhat': diff --git a/test/integration/roles/test_uri/tasks/main.yml b/test/integration/roles/test_uri/tasks/main.yml index 8891bff00e0..a9db1dedb00 100644 --- a/test/integration/roles/test_uri/tasks/main.yml +++ b/test/integration/roles/test_uri/tasks/main.yml @@ -279,3 +279,10 @@ state: absent with_items: "{{ uri_os_packages[ansible_os_family] }}" when: not ansible_python.has_sslcontext and not is_ubuntu_precise|bool + +- name: validate the status_codes are correct + uri: + url: https://httpbin.org/status/202 + status_code: 202 + method: POST + body: foo