# get content from URL header

**URL:** <https://forum.ansible.com/t/get-content-from-url-header/24740>\
**Category:** Ansible Project\
**Created:** [June 15, 2017, 6:45pm UTC](https://forum.ansible.com/t/get-content-from-url-header/24740 "2017-06-15T18:45:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Hugel](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@Christian\_Hugel](https://forum.ansible.com/u/Christian_Hugel)\
**Post date:** [June 15, 2017, 6:45pm UTC](https://forum.ansible.com/t/get-content-from-url-header/24740/1 "2017-06-15T18:45:22Z")

</div>

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](https://wordpress.org/latest.tar.gz) header  
shell: curl --silent --head [https://wordpress.org/latest.tar.gz](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](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](https://wordpress.org/latest.tar.gz)  
uri:  
url: [https://wordpress.org/latest.tar.gz](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](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](https://wordpress.org/latest.tar.gz%5Cn) ^ here\n”}

`

Can you guys give me a hand 😉 Thanks

Cheers,

C.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 15, 2017, 7:21pm UTC](https://forum.ansible.com/t/get-content-from-url-header/24740/2 "2017-06-15T19:21:19Z")

</div>

> 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](https://wordpress.org/latest.tar.gz) header  
> &nbsp;&nbsp;&nbsp;shell: curl --silent --head [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz) | grep  
> MD5 | awk '{print$2}'  
> &nbsp;&nbsp;&nbsp;register: md5sum\_wordpress
> 
> - name: Download WordPress  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get\_url:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checksum: md5:"{{ md5sum\_wordpress.stdout }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/wordpress.tar.gz  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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](https://wordpress.org/latest.tar.gz)  
> &nbsp;&nbsp;&nbsp;uri:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: HEAD  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return\_content: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;headers:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content-MD5:"{{ md5sum\_wordpress }}"

To do is the "Ansible way" it should be something like this

&nbsp;&nbsp;&nbsp;- name: Check MD5 sum of [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uri:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: HEAD  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: result

&nbsp;&nbsp;&nbsp;- name: Download WordPress  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get\_url:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: [https://wordpress.org/latest.tar.gz](https://wordpress.org/latest.tar.gz)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;checksum: md5:{{ result.content\_md5 }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/wordpress.tar.gz  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate\_certs: yes

---

<div class="post-metadata">

**Author:** ![Christian\_Hugel](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@Christian\_Hugel](https://forum.ansible.com/u/Christian_Hugel)\
**Post date:** [June 15, 2017, 7:28pm UTC](https://forum.ansible.com/t/get-content-from-url-header/24740/3 "2017-06-15T19:28:41Z")

</div>

You´re a genius! Thank you
