Ansible 'Failure Downloading' Error: Fix get_url & uri Module Issues
By Luca Berton · Published 2024-01-01 · Category: troubleshooting
Fix Ansible 'failure downloading' errors with get_url and uri modules. Covers SSL certificate issues, proxy settings, timeouts, and authentication for file.

Introduction
Today, we delve into Ansible troubleshooting, specifically addressing the "failure downloading" error. When attempting to download content from the internet, encountering the failure downloading error can be a stumbling block. This article explores the root causes of this error and provides practical solutions to overcome it.
See also: Ansible 'fatal: template error while templating string' Fix (Guide)
Understanding the failure downloading Error
Downloading content from the internet can sometimes result in the failure downloading error. This issue is often triggered by a misspelled URL or content being moved by the website. In many cases, the error is associated with an HTTP 404 error, indicating that the requested resource was not found. To mitigate this, it's crucial to double-check the URL in your browser before using it in Ansible.
A wrong URL, leading to an HTTP 404 error, is a common cause of the Ansible error failure downloading.
I'm Luca Berton, and welcome to today's episode of Ansible Pilot.
Live Demo: Solving the failure downloading Error
The best way to address Ansible troubleshooting is through a live Playbooknstration. In this video, we will practically explore the failure downloading error and demonstrate how to solve it.
Code
•failuredownloading_error.yml
---
- name: unarchive module Playbook
hosts: all
become: false
vars:
myurl: "https://github.com/lucab85/ansible-pilot/archive/refs/master.zip"
tasks:
- name: extract archive
ansible.builtin.unarchive:
src: "{{ myurl }}"
dest: "/home/devops/"
remote_src: true
validate_certs: true
• failuredownloading_fix.yml
---
- name: unarchive module Playbook
hosts: all
become: false
vars:
myurl: "https://github.com/lucab85/ansible-pilot/archive/refs/heads/master.zip"
tasks:
- name: extract archive
ansible.builtin.unarchive:
src: "{{ myurl }}"
dest: "/home/devops/"
remote_src: true
validate_certs: true
See also: Ansible 'Destination Does Not Exist' Error: Fix Path Issues
Conclusion: Troubleshooting the Ansible failure downloading Error
With the insights gained from the live Playbook and code examples, you now have a better understanding of how to troubleshoot and resolve the Ansible failure downloading error. Remember to verify your URLs, especially checking for HTTP 404 errors, to ensure smooth execution of your Ansible playbooks.
Common Download Errors and Fixes
Error: SSL certificate verify failed
fatal: [server]: FAILED! => {"msg": "Failed to validate the SSL certificate for download.example.com"}
Fix 1: Update CA certificates
- name: Update CA certificates (Debian/Ubuntu)
ansible.builtin.apt:
name: ca-certificates
state: latest
update_cache: true
become: true
Fix 2: Disable SSL validation (testing only)
- name: Download without SSL verification
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
validate_certs: false # NOT for production!
Error: Connection timed out
- name: Download with extended timeout
ansible.builtin.get_url:
url: https://example.com/large-file.iso
dest: /tmp/large-file.iso
timeout: 300 # 5 minutes (default is 10 seconds)
Error: 403 Forbidden / 401 Unauthorized
- name: Download with authentication
ansible.builtin.get_url:
url: https://example.com/private/file.tar.gz
dest: /tmp/file.tar.gz
url_username: myuser
url_password: "{{ vault_download_password }}"
force_basic_auth: true
# Or with token/header auth
- name: Download with bearer token
ansible.builtin.get_url:
url: https://api.example.com/releases/latest
dest: /tmp/release.tar.gz
headers:
Authorization: "Bearer {{ api_token }}"
Error: Download through proxy
- name: Download through corporate proxy
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
environment:
http_proxy: http://proxy.corp.com:3128
https_proxy: http://proxy.corp.com:3128
no_proxy: "localhost,127.0.0.1,.corp.com"
See also: Ansible 'chgrp failed' Error: Fix Group Ownership Permission Issues
Download with Checksum Verification
- name: Download and verify checksum
ansible.builtin.get_url:
url: https://releases.hashicorp.com/terraform/1.8.0/terraform_1.8.0_linux_amd64.zip
dest: /tmp/terraform.zip
checksum: "sha256:abc123def456..."
mode: '0644'
Retry Failed Downloads
- name: Download with retries
ansible.builtin.get_url:
url: https://example.com/file.tar.gz
dest: /tmp/file.tar.gz
timeout: 60
register: download_result
retries: 3
delay: 10
until: download_result is succeeded
get_url vs uri vs command+curl
| Module | Best For |
|--------|----------|
| get_url | Download files to disk |
| uri | API calls, checking URLs, small responses |
| command + curl | Complex scenarios (last resort) |
FAQ
Why does get_url fail but curl works?
Usually Python SSL/TLS library differences. Ansible uses Python's urllib, which may have different CA bundles than system curl. Update ca-certificates and python3-certifi.
How do I resume a partial download?
get_url doesn't support resume. Use command with curl -C - or wget -c for resumable downloads.
How do I download from S3?
Use the amazon.aws.aws_s3 module instead of get_url:
- name: Download from S3
amazon.aws.aws_s3:
bucket: my-bucket
object: /path/to/file.tar.gz
dest: /tmp/file.tar.gz
mode: get
Related Articles
• how Ansible become works under the hood • structuring playbooks with Ansible rolesCategory: troubleshooting
Watch the video: Ansible 'Failure Downloading' Error: Fix get_url & uri Module Issues — Video Tutorial