Ansible get_url Module: Download Files from URLs (ansible.builtin.get_url Guide)
By Luca Berton · Published 2024-01-01 · Category: installation
How to download files from URLs with Ansible get_url module (ansible.builtin.get_url). HTTP/HTTPS downloads, checksum validation, authentication. Practical YAML playbook examples.
The ansible.builtin.get_url module downloads files from HTTP, HTTPS, and FTP URLs to remote hosts. It handles checksums, authentication, proxies, timeouts, and conditional downloads — the Ansible equivalent of wget or curl.
Basic Usage
Download a File
Download with Checksum Verification
Set Ownership and Permissions
Common Parameters
| Parameter | Description | Default | |-----------|-------------|---------| | url | Download URL (required) | — | | dest | Destination path (required) | — | | checksum | Verify download integrity | — | | mode | File permissions | — | | owner | File owner | — | | group | File group | — | | force | Download even if file exists | false | | timeout | Download timeout (seconds) | 10 | | url_username | HTTP Basic Auth username | — | | url_password | HTTP Basic Auth password | — | | headers | Custom HTTP headers | — | | validate_certs | Verify SSL certificates | true | | backup | Create backup of existing file | false | | tmp_dest | Temp download directory | — |
Authentication
HTTP Basic Auth
Bearer Token
GitHub Release (Private Repo)
Proxy Configuration
Idempotent Downloads
Real-World Patterns
Download and Extract
Download Multiple Files
Install Binary from GitHub
Handle Self-Signed Certificates
Windows Equivalent
FAQ
How do I download a file with Ansible?
Use the get_url module: ansible.builtin.get_url: url=https://example.com/file.tar.gz dest=/tmp/file.tar.gz. It supports HTTP, HTTPS, and FTP. Add checksum for integrity verification.
How do I verify checksums with get_url?
Use the checksum parameter: checksum: sha256:abc123.... You can also point to a checksum URL: checksum: "sha256:https://example.com/file.sha256". Ansible verifies after download and fails if mismatched.
Is get_url idempotent?
Yes — if the destination file exists and matches the checksum, it's skipped. Without a checksum, it checks file size and modification time. Use force: true to always re-download.
How do I download through a proxy?
Set proxy environment variables on the task: environment: {https_proxy: "http://proxy:3128"}. Or configure system-wide in group_vars.
What is the difference between get_url and uri?
get_url downloads files to disk. uri makes HTTP requests and returns the response body — better for API calls. Use get_url for downloading files, uri for REST API interactions.
Conclusion • url + dest — Download file to remote host • checksum: sha256:... — Verify integrity (always use in production) • mode/owner/group — Set file permissions on download • force: true — Re-download even if file exists • environment: {https_proxy: ...} — Download through proxy • Windows: Use ansible.windows.win_get_url
Related Articles • Ansible unarchive Module: Extract Archives • Ansible uri Module: HTTP/REST API Calls • Ansible copy Module
Category: installation