Midokate
Midokate

Reputation: 95

Checking Checksum of a file from a url

I want to check the sha1 hash of file from a url.

- name: Download CONF WEB/WS/CORE files
  get_url:
    url: "{{ file.url }}"
    checksum: "sha1:{{ file.url }}.sha1"
    dest: "/home/file"
    force_basic_auth: yes
    url_username: "xxxx"
    url_password: "xxxxx"
    mode: 0640
    timeout: 300
    force: yes

i have a file located in http://domaine.com/file and the checksum located in http://domaine.com/file.sha1

when i execute the playbook i get this error message:

The checksum parameter has to be in format <algorithm>:<checksum> the example in ansible documentation is as below:

Ansible documentation : If a checksum is passed to this parameter, the digest of the destination file will be calculated after it is downloaded to ensure its integrity and verify that the transfer completed successfully. Format: :, e.g. checksum="sha256:D98291AC[...]B6DC7B97", checksum="sha256:http://example.com/path/sha256sum.txt"

Did someone encountered the same errors Thanks for your help in advance ^^,

Upvotes: 0

Views: 5248

Answers (1)

Hernan Garcia
Hernan Garcia

Reputation: 1614

Due to this comment it seems they won't provide such feature to check the checksum against an URL https://github.com/ansible/ansible/issues/48790#issuecomment-440432038

It seems you need to do it in two separated tasks, one to download the checksum file and a second task to extract the checksum value from the downloaded file

I did this

---
- hosts: localhost
  tasks:
  - name: Download file
    get_url:
      url: "http://localhost/file"
      checksum: "sha1:3b71f43ff30...e84eb5a3"
      dest: "/home/user/file"

and it worked

Related issues
https://github.com/ansible/ansible/issues/27617
https://github.com/ansible/ansible/issues/48790
https://github.com/ansible/ansible/issues/48847

Upvotes: 1

Related Questions