get content from URL header

42 views
Skip to first unread message

Christian Hügel

unread,
Jun 15, 2017, 2:47:16 PM6/15/17
to Ansible Project
Hi,


I need to get the content (md5 checksum) from the header of a url. This could be done with:

- name: Get md5sum from https://wordpress.org/latest.tar.gz header
  shell
: curl --silent --head https://wordpress.org/latest.tar.gz | grep MD5 | awk '{print$2}'
 
register: md5sum_wordpress

- name: Download WordPress
    get_url
:
        url
: https://wordpress.org/latest.tar.gz
        checksum
: md5:"{{ md5sum_wordpress.stdout }}"
        dest
: /tmp/wordpress.tar.gz
        validate_certs
: yes



but ansible throws a warning to use uri instead but I´ve tried different combinations like:

- name: Check MD5 sum of https://wordpress.org/latest.tar.gz
  uri
:
    url
: https://wordpress.org/latest.tar.gz
    method
: HEAD
    return_content
: yes
    headers
:
     
Content-MD5:"{{ md5sum_wordpress }}"



but it doesn´t work.

TASK [create_wordpress : Check MD5 sum of https://wordpress.org/latest.tar.gz] ********************
fatal
: [ansible]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'md5sum_wordpress' is undefined\n\nThe error appears to have been in '/root/ansible/lxd-containers/roles/create_wordpress/tasks/main.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# tasks file for wordpress\n- name: Check MD5 sum of https://wordpress.org/latest.tar.gz\n  ^ here\n"}



Can you guys give me a hand ;) Thanks

Cheers,

C.

Kai Stian Olstad

unread,
Jun 15, 2017, 3:21:53 PM6/15/17
to ansible...@googlegroups.com
On 15. juni 2017 20:45, Christian Hügel wrote:
> I need to get the content (md5 checksum) from the header of a url. This
> could be done with:
>
> - name: Get md5sum from https://wordpress.org/latest.tar.gz header
> shell: curl --silent --head https://wordpress.org/latest.tar.gz | grep
> MD5 | awk '{print$2}'
> register: md5sum_wordpress
>
> - name: Download WordPress
> get_url:
> url: https://wordpress.org/latest.tar.gz
> checksum: md5:"{{ md5sum_wordpress.stdout }}"
> dest: /tmp/wordpress.tar.gz
> validate_certs: yes
>
>
>
> but ansible throws a warning to use uri instead but I´ve tried different
> combinations like:

The reason you are getting a warning(it actually only a tip) is that
Ansible sees that your are using curl in the shell module, and comes
with a suggestion to use uri.

You don't have to. You could add "warn: false" on the shell task or turn
off this type on warning in ansible.cfg.


> - name: Check MD5 sum of https://wordpress.org/latest.tar.gz
> uri:
> url: https://wordpress.org/latest.tar.gz
> method: HEAD
> return_content: yes
> headers:
> Content-MD5:"{{ md5sum_wordpress }}"
To do is the "Ansible way" it should be something like this

- name: Check MD5 sum of https://wordpress.org/latest.tar.gz
uri:
url: https://wordpress.org/latest.tar.gz
method: HEAD
register: result

- name: Download WordPress
get_url:
url: https://wordpress.org/latest.tar.gz
checksum: md5:{{ result.content_md5 }}
dest: /tmp/wordpress.tar.gz
validate_certs: yes

--
Kai Stian Olstad

Christian Hügel

unread,
Jun 15, 2017, 3:28:42 PM6/15/17
to Ansible Project, ansible-pr...@olstad.com
You´re a genius! Thank you
Reply all
Reply to author
Forward
0 new messages