Idempotent fetching of files by URL

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?

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

A workaround with get_url.

- get_url:
     url: http://…
     dest: /tmp/tempfile
     force: yes
   delegate_to: localhost
   changed_when: false

- copy:
     src: /tmp/tempfile
     dest: /path.....

Try

Force: no

I think that will work, although I use win_get_url more than get_url

Jon

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.

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.

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.