diff --git a/changelogs/fragments/fix-open-url.yml b/changelogs/fragments/fix-open-url.yml new file mode 100644 index 00000000000..c8c47e4001b --- /dev/null +++ b/changelogs/fragments/fix-open-url.yml @@ -0,0 +1,2 @@ +bugfixes: +- urls - Only assume GET method if data is empty, otherwise POST diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 6f6508500c6..25dc35504eb 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -1136,7 +1136,7 @@ def open_url(url, data=None, headers=None, method=None, use_proxy=True, Does not require the module environment ''' - method = method or 'GET' + method = method or ('POST' if data else 'GET') return Request().open(method, url, data=data, headers=headers, use_proxy=use_proxy, force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs, url_username=url_username, url_password=url_password, http_agent=http_agent,