From 1cd4369815732b0f588f99fa4879f840daf47aab Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 8 Sep 2025 07:44:17 -0700 Subject: [PATCH] fetch_file: add ca_path and cookies parameters (#85187) * Added ca_path and cookies parameter arguments to fetch_file method to specify CA path and Cookies to fetch file from URL. These parameters are already supported by fetch_url. Fixes: #85172 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/fetch_file.yml | 3 +++ lib/ansible/module_utils/urls.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fetch_file.yml diff --git a/changelogs/fragments/fetch_file.yml b/changelogs/fragments/fetch_file.yml new file mode 100644 index 00000000000..35c7e8412d0 --- /dev/null +++ b/changelogs/fragments/fetch_file.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - fetch_file - add ca_path and cookies parameter arguments (https://github.com/ansible/ansible/issues/85172). diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index 9316dc16091..a1e36a6c5ce 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -1358,7 +1358,8 @@ def _split_multiext(name, min=3, max=4, count=2): def fetch_file(module, url, data=None, headers=None, method=None, use_proxy=True, force=False, last_mod_time=None, timeout=10, - unredirected_headers=None, decompress=True, ciphers=None): + unredirected_headers=None, decompress=True, ciphers=None, + ca_path=None, cookies=None): """Download and save a file via HTTP(S) or FTP (needs the module as parameter). This is basically a wrapper around fetch_url(). @@ -1375,6 +1376,8 @@ def fetch_file(module, url, data=None, headers=None, method=None, :kwarg unredirected_headers: (optional) A list of headers to not attach on a redirected request :kwarg decompress: (optional) Whether to attempt to decompress gzip content-encoded responses :kwarg ciphers: (optional) List of ciphers to use + :kwarg ca_path: (optional) Path to CA bundle + :kwarg cookies: (optional) CookieJar object to send with the request :returns: A string, the path to the downloaded file. """ @@ -1386,7 +1389,8 @@ def fetch_file(module, url, data=None, headers=None, method=None, module.add_cleanup_file(fetch_temp_file.name) try: rsp, info = fetch_url(module, url, data, headers, method, use_proxy, force, last_mod_time, timeout, - unredirected_headers=unredirected_headers, decompress=decompress, ciphers=ciphers) + unredirected_headers=unredirected_headers, decompress=decompress, ciphers=ciphers, + ca_path=ca_path, cookies=cookies) if not rsp or (rsp.code and rsp.code >= 400): module.fail_json(msg="Failure downloading %s, %s" % (url, info['msg'])) data = rsp.read(bufsize)