Loading...

Watch: Download a file using an HTTPS proxy via environment variables - Ansible get_url and environment

Learn how to download files using Ansible get_url module with proxy settings, including checksum verification and setting file permissions.

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: [d

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