AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible get_url Module: Download Files from URLs (ansible.builtin.get_url Guide) — Video Tutorial
Complete guide to Ansible get_url module (ansible.builtin.get_url). Download files from HTTP, HTTPS, and FTP URLs with checksum verification and authentication.
What You'll Learn
- How to download a file with Ansible?
- Ansible download a file
- Main Parameters
- Conclusion
- Download Examples
- Download with checksum
- Download with authentication
- Download with retries
- Download only if changed (conditional)
- Download through proxy
Full Tutorial Content
How to download a file with Ansible?
I'm going to show you a live Playbook and some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible download a file
Today we're talking about the Ansible module `get_url`.
The full name is `ansible.builtin.get_url`, which means that is part of the collection of modules "builtin" with ansible and shipped with it, part of `ansible-core`.
It's a module pretty stable and out for years.
It works in a different variety of operating systems.
It downloads files from HTTP, HTTPS, or FTP to node
For Windows targets, use the `ansible.windows.win_get_url` module instead.
Main Parameters
- `url` string - URL
- `dest` string - path
- `force` string - no/yes
- `checksum` string - \
:\
- `force_basic_auth`/`url_username`/`url_password`/use_gssapi - HTTP basic auth/GSSAPI-Kerberos
- `headers` dictionary - custom HTTP headers
- `http_agent` string - "ansible-httpget"
- `owner`/`group`/`mode` string - permission
- `setype`/`seuser`/`selevel` - SELinux
This module has some parameters to perform any tasks.
The two required parameters are `url` and `dest`.
The `url` parameter specifies the URL of the resource you're going to download.
The `dest` parameter specifies the filesystem path where the resource is going to be saved on the target node.
Let's deep dive in the "force" parameter.
If "dest" is a file, Ansible is going to download every time the file. If "dest" is a directory the default behavior is not to replace a file, until you toggle to `yes` the force parameter.
The parameter "checksum" is very useful to validate the consistency of the downloaded file.
You could specify the algorithm, usually sha1 or sha256, and directly the checksum or a URL for checksum.
You might need the third-party `hashlib` library for access to additional algorithms.
Another interesting parameter is "headers" which allow you to specify some custom HTTP headers.
Ansible presents himself as "ansible-httpget" in the web server logs, but you cust customize it in the "http_agent" parameter.
There are some additional parameters for authentication for example to handle HTTP basic authentication with username and password or for more complex GSSAPI-Kerberos scenarios using `httplib2` Python library.
Let me also highlight that we could also specify the permission and SELinux properties.
## Playbook
Let's jump in a real-life playbook on how to download a file with Ansible.
- get_url.yml
```yaml
---
- name: get_url module Playbook
hosts: all
become: false
vars:
myurl: "https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz"
mycrc: "sha256:https://releases.ansible.com/ansible/ansible-2.9.25.tar.gz.sha"
mydest: "/home/devops"
tasks:
- name: download file
ansible.builtin.get_url:
url: "{{ myurl }}"
dest: "{{ mydest }}"
checksum: "{{ mycrc }}"
mode: '0644'
owner: devops
group: wheel
```
[code with ❤️ in GitHAbout This Tutorial
- Author: Luca Berton
- Difficulty: Advanced
- Read time: 8 min
- Category: installation
Read the full written article: Ansible get_url Module: Download Files from URLs (ansible.builtin.get_url Guide)
Related Video Tutorials
- Ansible 'Destination Does Not Exist' Error: Fix Path Issues — Fix Ansible destination does not exist error. Resolve missing parent directories, wrong paths, and permission issues for copy, template, and file modules.
- Ansible 'urlopen error' Fix: SSL, Proxy & Network Connection Issues — Fix Ansible urlopen error for SSL certificate failures, proxy issues, DNS resolution, and network timeouts. Troubleshoot uri, get_url, and pip module connection errors.
- Download a file in Windows-like systems - Ansible module win_get_url — Learn how to download files using Ansible's win_get_url module on Windows, with a step-by-step guide and example playbook.
- How to install Ansible in Oracle Linux 8 - Ansible install — Learn how to install the latest Ansible release on Oracle Linux 8 using the oracle-epel-release-el8 repository with a simple script.
- Ansible Set File Permissions 755: chmod with file Module Guide — How to set file permissions with Ansible file module. Add execute permission (755, 644, 600), manage ownership, and apply permissions recursively.
- How to Add a Disk to a VMware VM Using Ansible Playbook — Learn how to add a disk to a VMware VM using an Ansible playbook. This guide includes the YAML configuration, variables, and execution steps for easy automation.