Ansible get_url Fails If Destination File Does Not Exist

3.1k views Asked by At

When using get_url, it fails if the destination file does not exist locally. If I us vi and create the file with nothing in it, then the call works and the file is replaced. I added force: yes to encourage it to write out the file, but every attempt failed until I created a dummy file.

Any help is appreciated.

Thank you!

---
- name: Download HashiCorp Installation Archive File
  hosts: 127.0.0.1

  vars:
    vault:
      distro:  'linux'
      version: '1.5.4'
    user:
      group: 'rcouch'
      name:  'rcouch'
  
  tasks:

    # https://releases.hashicorp.com/vault/1.5.4/vault_1.5.4_linux_amd64.zip
    - name: Download Binary
      get_url:
        url:      "https://releases.hashicorp.com/vault/{{ vault.version }}/vault_{{ vault.version }}_{{ vault.distro }}_amd64.zip"
        checksum: "sha256:https://releases.hashicorp.com/vault/{{ vault.version }}/vault_{{ vault.version }}_SHA256SUMS"
        force:    yes
        dest:     "vault_{{ vault.version }}_{{ vault.distro }}_amd64.zip"
        owner:    "{{ user.group }}"
        group:    "{{ user.name }}"
        mode:     0755
      register: vault_download
  
    - name: Display Vault Download
      debug:
        msg:
        - "vault_download: {{ vault_download }}"

1

There are 1 answers

1
seshadri_c On BEST ANSWER

The get_url module takes an absolute path in dest. A small excerpt from the module's page. Try an absolute path like /tmp or ./.

| dest | Absolute path of where to download the file to. |

  tasks:
  - get_url:
      url: https://releases.hashicorp.com/vault/1.5.4/vault_1.5.4_linux_amd64.zip
      dest: ./vault_1.5.4_linux_amd64.zip