Ansible Download From: Url And Unzip _verified_
- name: Download the zip file from a URL ansible.builtin.get_url: url: "https://example.com" dest: "/tmp/software.zip" checksum: "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" # Recommended for security mode: '0644' Use code with caution. Step 2: Extract with unarchive
Using Ansible to download a file from a URL and unzip it is a fundamental task for automating software installations and artifact deployments. You can accomplish this using two primary methods: combining the and unarchive modules for maximum control, or using the unarchive module alone for a streamlined "one-shot" approach . Method 1: The Two-Step Approach (Recommended) ansible download from url and unzip
- name: Unzip the downloaded file ansible.builtin.unarchive: src: "/tmp/software.zip" dest: "/opt/software/" remote_src: yes creates: "/opt/software/bin/main_executable" # Avoids re-unzipping if files exist Use code with caution. Method 2: The Direct "One-Step" Approach - name: Download the zip file from a URL ansible
The ansible.builtin.get_url module handles the download. It supports HTTP, HTTPS, and FTP protocols. Method 1: The Two-Step Approach (Recommended) - name:
Once the file is on the target machine, the ansible.builtin.unarchive module extracts it. Crucially, you must set remote_src: yes because the file already exists on the remote host.
The unarchive module can download and extract in a single task if you provide a URL as the src . While convenient, this method lacks the detailed checksum verification found in get_url .