AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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.
Download a file using an HTTPS proxy via environment variables - Ansible get_url and environment — Video Tutorial
Learn how to download files using Ansible get_url module with proxy settings, including checksum verification and setting file permissions.
What You'll Learn
- How to download a file using an HTTPS proxy via environment variables with Ansible?
- Download a file using an https proxy via env variables
- code
- execution
- idempotency
- before execution
- after execution
- Conclusion
- Related Articles
- Proxy Configuration Methods
Full Tutorial Content
How to download a file using an HTTPS proxy via environment variables with Ansible?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Download a file using an https proxy via env variables
- `get_url` module
- `http_proxy` and `https_proxy` environment
The easiest way to download a file using an HTTPS proxy is via the `get_url` Ansible module and the environment variables.
You could set the remote proxy via the `http_proxy` and `https_proxy` remote environment using the Ansible statement `environment`.
This applies respectively to HTTP and HTTPS connections.
The Ansible `environment` statement could be applied at the task level or play level.
## Playbook
Download a file using an HTTPS proxy via environment variables with Ansible Playbook.
The following scenario uses the HTTPS proxy server http://proxy.example.com:3128.
code
```yaml
---
- name: get_url module with proxy Playbook
hosts: all
become: false
gather_facts: 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/ansible-2.9.25.tar.gz"
tasks:
- name: download file with proxy
ansible.builtin.get_url:
url: "{{ myurl }}"
dest: "{{ mydest }}"
checksum: "{{ mycrc }}"
mode: '0644'
owner: devops
group: wheel
environment:
https_proxy: "http://proxy.example.com:3128"
```
execution
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory download\ file/get_url_with_proxy.yml
PLAY [get_url module with proxy Playbook] *************************************************************
TASK [download file with proxy] *******************************************************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible-pilot $
```
idempotency
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory download\ file/get_url_with_proxy.yml
PLAY [get_url module with proxy Playbook] *************************************************************
TASK [download file with proxy] *******************************************************************
ok: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible-pilot $
```
before execution
```bash
ansible-pilot $ ssh devops@demo.example.com
Last login: Mon Feb 21 14:34:39 2022 from 192.168.251.111
[devops@demo ~]$ ls -al
total 16
drwx------. 4 devops wheel 111 Feb 21 14:29 .
drwxr-xr-x. 4 root root 35 Jan 5 10:18 ..
drwx------.
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 4 min
- Category: installation
Read the full written article: Download a file using an HTTPS proxy via environment variables - Ansible get_url and environment
Related Video Tutorials
- Ansible environment Keyword: Set Environment Variables Per Task or Play — How to set environment variables per task or play in Ansible using the environment keyword. Configure proxy, PATH, and app-specific variables with examples.
- Ansible Set Environment Variables: lineinfile for /etc/environment & .bashrc — How to permanently set system-wide and user-level environment variables on Linux with Ansible. Use lineinfile for /etc/environment, profile.d, and .bashrc.
- Deploy Squid Proxy on RedHat Systems with Ansible — Learn to deploy and configure a Squid proxy server on RedHat-like systems using Ansible. Follow our step-by-step guide with simple Ansible code examples.
- Ansible Write to File: Variable Content with copy & template Modules — How to write variables to files in Ansible. Compare copy content vs template module, write JSON/YAML, and generate dynamic config files with examples.
- 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.