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.

Watch Video

Watch "Download a file using an HTTPS proxy via environment variables - Ansible get_url and environment" on YouTube

What You'll Learn

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

Read the full written article: Download a file using an HTTPS proxy via environment variables - Ansible get_url and environment

Topics Covered

Related Video Tutorials