From 2b65166a29b07e5fb3cb5e811fc6150b38664cc3 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 1 May 2024 19:43:22 -0700 Subject: [PATCH] uri: deprecate 'yes' or 'no' value in follow_redirects param (#83169) * uri (module and lookup): deprecate 'yes' or 'no' value in follow_redirects param Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/uri_follow_redirect.yml | 3 +++ lib/ansible/modules/uri.py | 21 +++++++++++++------- lib/ansible/plugins/lookup/url.py | 17 ++++++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/uri_follow_redirect.yml diff --git a/changelogs/fragments/uri_follow_redirect.yml b/changelogs/fragments/uri_follow_redirect.yml new file mode 100644 index 00000000000..1df21a486cb --- /dev/null +++ b/changelogs/fragments/uri_follow_redirect.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - uri - deprecate 'yes' and 'no' value for 'follow_redirects' parameter. diff --git a/lib/ansible/modules/uri.py b/lib/ansible/modules/uri.py index d721c02487f..51c47561855 100644 --- a/lib/ansible/modules/uri.py +++ b/lib/ansible/modules/uri.py @@ -107,15 +107,16 @@ options: default: no follow_redirects: description: - - Whether or not the URI module should follow redirects. V(all) will follow all redirects. - V(safe) will follow only "safe" redirects, where "safe" means that the client is only - doing a GET or HEAD on the URI to which it is being redirected. V(none) will not follow - any redirects. Note that V(true) and V(false) choices are accepted for backwards compatibility, - where V(true) is the equivalent of V(all) and V(false) is the equivalent of V(safe). V(true) and V(false) - are deprecated and will be removed in some future version of Ansible. + - Whether or not the URI module should follow redirects. type: str - choices: ['all', 'no', 'none', 'safe', 'urllib2', 'yes'] default: safe + choices: + all: Will follow all redirects. + none: Will not follow any redirects. + safe: Only redirects doing GET or HEAD requests will be followed. + urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects). + 'no': (DEPRECATED, removed in 2.22) alias of V(none). + 'yes': (DEPRECATED, removed in 2.22) alias of V(all). creates: description: - A filename, when it already exists, this step will not be run. @@ -580,6 +581,12 @@ def uri(module, url, dest, body, body_format, method, headers, socket_timeout, c # if destination file already exist, only download if file newer kwargs['last_mod_time'] = utcfromtimestamp(os.path.getmtime(dest)) + if module.params.get('follow_redirects') in ('no', 'yes'): + module.deprecate( + "Using 'yes' or 'no' for 'follow_redirects' parameter is deprecated.", + version='2.22' + ) + resp, info = fetch_url(module, url, data=data, headers=headers, method=method, timeout=socket_timeout, unix_socket=module.params['unix_socket'], ca_path=ca_path, unredirected_headers=unredirected_headers, diff --git a/lib/ansible/plugins/lookup/url.py b/lib/ansible/plugins/lookup/url.py index 2e8b9b4730e..4775ecfb0c4 100644 --- a/lib/ansible/plugins/lookup/url.py +++ b/lib/ansible/plugins/lookup/url.py @@ -99,12 +99,12 @@ options: - section: url_lookup key: follow_redirects choices: - - urllib2 - - all - - 'yes' - - safe - - none - - 'no' + all: Will follow all redirects. + none: Will not follow any redirects. + safe: Only redirects doing GET or HEAD requests will be followed. + urllib2: Defer to urllib2 behavior (As of writing this follows HTTP redirects). + 'no': (DEPRECATED, removed in 2.22) alias of V(none). + 'yes': (DEPRECATED, removed in 2.22) alias of V(all). use_gssapi: description: - Use GSSAPI handler of requests @@ -234,6 +234,11 @@ class LookupModule(LookupBase): ret = [] for term in terms: display.vvvv("url lookup connecting to %s" % term) + if self.get_option('follow_redirects') in ('yes', 'no'): + display.deprecated( + "Using 'yes' or 'no' for 'follow_redirects' parameter is deprecated.", + version='2.22' + ) try: response = open_url( term, validate_certs=self.get_option('validate_certs'),