# Idempotent fetching of files by URL

**URL:** <https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464>\
**Category:** Ansible Project\
**Created:** [January 11, 2018, 9:02pm UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464 "2018-01-11T21:02:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Smift2](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Josh\_Smift2](https://forum.ansible.com/u/Josh_Smift2)\
**Post date:** [January 11, 2018, 9:02pm UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464/1 "2018-01-11T21:02:43Z")

</div>

There doesn’t seem to be a way to fetch a file by URL that meets both of these criteria:

- When run without --check, replaces the dest file with the contents of the source file if and only if they’re different.
- When run with --check, correctly tells you whether anything would change if you run it without --check.

Doesn’t that sound simple? I can’t figure out how to do it, with either get\_url or unarchive. :^( Is there a way?

---

<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:** [January 12, 2018, 8:29am UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464/2 "2018-01-12T08:29:16Z")

</div>

One solution is to make a pull request to add the functionality.

A workaround with get\_url.

- get\_url:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: http://…  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp/tempfile  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;force: yes  
&nbsp;&nbsp;&nbsp;delegate\_to: localhost  
&nbsp;&nbsp;&nbsp;changed\_when: false

- copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /tmp/tempfile  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /path.....

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [January 13, 2018, 9:56am UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464/3 "2018-01-13T09:56:55Z")

</div>

Try

Force: no

I think that will work, although I use win\_get\_url more than get\_url

Jon

---

<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:** [January 13, 2018, 10:21am UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464/4 "2018-01-13T10:21:20Z")

</div>

It wont, get\_url always report changed in check mode regardless of force is yes or no and if the file is the same or not.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift2](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Josh\_Smift2](https://forum.ansible.com/u/Josh_Smift2)\
**Post date:** [January 13, 2018, 4:24pm UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464/5 "2018-01-13T16:24:14Z")

</div>

Yar; and also, force: no means that it doesn’t even check if the file has changed, whether in --check mode or not – if the file exists, it doesn’t do anything, even if the contents are wrong.

---

<div class="post-metadata">

**Author:** ![Josh\_Smift2](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@Josh\_Smift2](https://forum.ansible.com/u/Josh_Smift2)\
**Post date:** [January 16, 2018, 8:16pm UTC](https://forum.ansible.com/t/idempotent-fetching-of-files-by-url/26464/6 "2018-01-16T20:16:08Z")

</div>

It turns out that unarchive with a .zip file basically works – except that on our Ubuntu 16.04 systems, for some reason, it deals with timezones in some bizarre way that I can try explain but won’t bother unless anyone really wants to know. As long as the zip files were built in the same timezone as the systems, it works just fine.

It seems very bizarre to me that zip would work in this way while tar doesn’t, but it is what it is. I don’t have the right combination of time and expertise to try to improve the module, alas.
