# Behavior of get\_url if file exists in destination?

**URL:** <https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071>\
**Category:** Ansible Project\
**Created:** [August 29, 2014, 12:12pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071 "2014-08-29T12:12:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Levi\_Notik](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Levi\_Notik](https://forum.ansible.com/u/Levi_Notik)\
**Post date:** [August 29, 2014, 12:12pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/1 "2014-08-29T12:12:20Z")

</div>

I’m trying to use get\_url to download a file to a group of hosts. My play looks like this:

`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 29, 2014, 12:33pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/2 "2014-08-29T12:33:22Z")

</div>

Hi Levi,

It looks like you need to use the “force” parameter, which is documented as follows:

If `yes` and `dest` is not a directory, will download the file every time and replace the file if the contents change. If `no`, the file will only be downloaded if the destination does not exist. Generally should be `yes`only for small local files. Prior to 0.6, this module behaved as if `yes` was the default. (added in Ansible 0.7)

(We can really remove all the special notes about 0.6 and 0.7, as that’s some very old stuff and everyone has upgraded at this point)

Also, usual disclaimer about get\_url: If you have more than one server, a good tip can be to use a local step in a preceeding play to download a file and then the copy module to move it out. This prevents using your server farm to unintentionally DDOS a particular website or service. 500 or 1000 machines downloading a tarball would be rather abusive, especially if using force=yes or deploying them all at the same time.

---

<div class="post-metadata">

**Author:** ![Levi\_Notik](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Levi\_Notik](https://forum.ansible.com/u/Levi_Notik)\
**Post date:** [August 29, 2014, 12:36pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/3 "2014-08-29T12:36:11Z")

</div>

I’ve tried with force: yes with everything else the same as above and that didn’t work.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 29, 2014, 12:41pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/4 "2014-08-29T12:41:09Z")

</div>

(A) please confirm what version of ansible you are using (ansible --version)

(B) when you say “didn’t work”, can you describe what did not work means? How did you ascertain it did not work?

---

<div class="post-metadata">

**Author:** ![Levi\_Notik](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Levi\_Notik](https://forum.ansible.com/u/Levi_Notik)\
**Post date:** [August 29, 2014, 12:47pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/5 "2014-08-29T12:47:30Z")

</div>

Version is 1.7.1

I’m probably missing something basic here (very new to ansible), but after running the playbook, I checked the directory on the host and the file hasn’t been modified. Similarly, the notify step of restarting the service doesn’t run (I know this by tailing logs).

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 29, 2014, 3:02pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/6 "2014-08-29T15:02:40Z")

</div>

here’s an easy thing to try:

ansible localhost -m get\_url -c local -a “url=[http://google.com](http://google.com) dest=/tmp/path force=no”  
Observe /tmp/path

edit /tmp/path to say “changeme this is a file that needs to be replaced”  
Run ansible command again  
observe /tmp/path is now replaced

---

<div class="post-metadata">

**Author:** ![Levi\_Notik](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Levi\_Notik](https://forum.ansible.com/u/Levi_Notik)\
**Post date:** [August 29, 2014, 3:04pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/7 "2014-08-29T15:04:01Z")

</div>

So I should be leaving off the filename in the dest param?

---

<div class="post-metadata">

**Author:** ![Levi\_Notik](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Levi\_Notik](https://forum.ansible.com/u/Levi_Notik)\
**Post date:** [August 29, 2014, 3:38pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/8 "2014-08-29T15:38:41Z")

</div>

Ok, I see that locally it does work with force=yes.

`  
➜ ~ ansible localhost -m get\_url -c local -a “url=[http://google.com](http://google.com) dest=/tmp/ansibletest/myfile.txt force=no”  
localhost | success \>\> {  
“changed”: true,  
“dest”: “/tmp/ansibletest/myfile.txt”,  
“gid”: 0,  
“group”: “wheel”,  
“md5sum”: “267350d45315532aff7aca36163ddc75”,  
“mode”: “0644”,  
“msg”: “OK (unknown bytes)”,  
“owner”: “levinotik”,  
“sha256sum”: “”,  
“size”: 19035,  
“src”: “/var/folders/j6/fdfzf9bj4rx2zgy1vjd9x5bm0000gn/T/tmpbC9W6D”,  
“state”: “file”,  
“uid”: 501,  
“url”: “[http://google.com](http://google.com)”  
}

➜ ~ cat /tmp/ansibletest/myfile.txt  
Google#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;overflow-y:scroll}#gog{padding:3px 8px 0}td{line-height:.8em}.gac\_m td{line-height:17px}form{margin-bottom:20px}.h{color:#36c}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}em{font-weight:bold;font-style:normal}.lst{height:25px;width:496px}.gsfi,.lst{font:18px arial,sans-serif}.gsfs{font:17px arial,sans-serif}.ds{display:inline-box;display:inline-block;margin:3px 0 4px;margin-left:4px}input{font-family:inherit}a.gb1,a.gb2,a.gb3,a.gb4{color:#11c !important}body{background:#fff;color:black}a{color:#11c;text-decoration:none}a:hover,a:active{text-decoration:underline}.fl a{color:#36c}a:visited{color:#551a8b}a.gb1,a.gb4{text-decoration:underline}a.gb3:hover{text-decoration:none}#ghead a.gb2:hover{color:#fff !important}.sblc{padding-top:5px}.sblc a{display:block;margin:2px 0;margin-left:13px;font-size:11px}.lsbb{background:#eee;border:solid 1px;border-color:#ccc #999 #999 #ccc;height:30px}.lsbb{display:block}.ftl,#fll a{display:inline-block;margin:0 12px}.lsb{background:url(/images/srpr/nav\_logo80.png) 0 -258px repeat-x;border:none;color:#000;cursor:pointer;height:30px;margin:0;outline:0;font:15px arial,sans-serif;vertical-align:top}.lsb:active{background:#ccc}.lst:focus{outline:none}#addlang a{padding:0 3px}

 
**Search** [Images](http://www.google.com/imghp?hl=en&tab=wi) [Maps](http://maps.google.com/maps?hl=en&tab=wl) [Play](https://play.google.com/?hl=en&tab=w8) [YouTube](http://www.youtube.com/?tab=w1) [News](http://news.google.com/nwshp?hl=en&tab=wn) [Gmail](https://mail.google.com/mail/?tab=wm) [Drive](https://drive.google.com/?tab=wo) [More »](http://www.google.com/intl/en/options/)

[Web History](http://www.google.com/history/optout?hl=en) | [Settings](https://forum.ansible.com/preferences?hl=en) | [Sign in](https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.com/)

 
 
.pmoabs{background-color:#fff;border:1px solid #E5E5E5;color:#666;font-size:13px;padding-bottom:20px;position:absolute;right:2px;top:3px;z-index:986}#pmolnk{border-radius:2px;-moz-border-radius:2px;-webkit-border-radius:2px}.kd-button-submit{border:1px solid #3079ed;background-color:#4d90fe;background-image:-webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#4787ed));background-image:-webkit-linear-gradient(top,#4d90fe,#4787ed);background-image:-moz-linear-gradient(top,#4d90fe,#4787ed);background-image:-ms-linear-gradient(top,#4d90fe,#4787ed);background-image:-o-linear-gradient(top,#4d90fe,#4787ed);background-image:linear-gradient(top,#4d90fe,#4787ed);filter:progid:DXImageTransform.Microsoft.gradient(startColorStr=‘#4d90fe’,EndColorStr=‘#4787ed’)}.kd-button-submit:hover{border:1px solid #2f5bb7;background-color:#357ae8;background-image:-webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#357ae8));background-image:-webkit-linear-gradient(top,#4d90fe,#357ae8);background-image:-moz-linear-gradient(top,#4d90fe,#357ae8);background-image:-ms-linear-gradient(top,#4d90fe,#357ae8);background-image:-o-linear-gradient(top,#4d90fe,#357ae8);background-image:linear-gradient(top,#4d90fe,#357ae8);filter:progid:DXImageTransform.Microsoft.gradient(startColorStr=‘#4d90fe’,EndColorStr=‘#357ae8’)}.kd-button-submit:active{-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);box-shadow:inset 0 1px 2px rgba(0,0,0,0.3)}#pmolnk a{color:#fff;display:inline-block;font-weight:bold;padding:5px 20px;text-decoration:none;white-space:nowrap}.xbtn{color:#999;cursor:pointer;font-size:23px;line-height:5px;padding-top:5px}.padi{padding:0 8px 0 10px}.padt{padding:5px 20px 0 0;color:#444}.pads{text-align:left;max-width:200px} 
 

 |   
×
  |
 | ![](https://sea1.discourse-cdn.com/ansible/images/icons/product/chrome-48.png) | A faster way to browse the web |
 |   
 [Install Google Chrome](https://forum.ansible.com/chrome/index.html?hl=en&brand=CHNG&utm_source=en-hpp&utm_medium=hpp&utm_campaign=en) 
  |
 
 

   

 ![Google](https://sea1.discourse-cdn.com/ansible/images/srpr/logo9w.png)  
  

| &nbsp; | 

  
 | [Advanced search](https://forum.ansible.com/advanced_search?hl=en&authuser=0)[Language tools](https://forum.ansible.com/language_tools?hl=en&authuser=0) |

  

[Advertising&nbsp;Programs](https://forum.ansible.com/intl/en/ads/)[Business Solutions](https://forum.ansible.com/services/)[+Google](https://plus.google.com/116899029375914044550)[About Google](https://forum.ansible.com/intl/en/about.html)

© 2013 - [Privacy & Terms](https://forum.ansible.com/intl/en/policies/)

 ➜ ~ echo -n “change me” \> /tmp/ansibletest/myfile.txt  
➜ ~ cat /tmp/ansibletest/myfile.txt  
change me ➜ ~ ansible localhost -m get\_url -c local -a “url=[http://google.com](http://google.com) dest=/tmp/ansibletest/myfile.txt force=no”  
localhost | success \>\> {  
“changed”: false,  
“dest”: “/tmp/ansibletest/myfile.txt”,  
“gid”: 0,  
“group”: “wheel”,  
“mode”: “0644”,  
“msg”: “file already exists”,  
“owner”: “levinotik”,  
“size”: 9,  
“state”: “file”,  
“uid”: 501,  
“url”: “[http://google.com](http://google.com)”  
}

➜ ~ cat /tmp/ansibletest/myfile.txt  
change me ➜ ~ ansible localhost -m get\_url -c local -a “url=[http://google.com](http://google.com) dest=/tmp/ansibletest/myfile.txt force=yes”  
localhost | success \>\> {  
“changed”: true,  
“dest”: “/tmp/ansibletest/myfile.txt”,  
“gid”: 0,  
“group”: “wheel”,  
“md5sum”: “3178fd55ddc36372ff0552dea545187e”,  
“mode”: “0644”,  
“msg”: “OK (unknown bytes)”,  
“owner”: “levinotik”,  
“sha256sum”: “”,  
“size”: 19067,  
“src”: “/var/folders/j6/fdfzf9bj4rx2zgy1vjd9x5bm0000gn/T/tmpEkHnl6”,  
“state”: “file”,  
“uid”: 501,  
“url”: “[http://google.com](http://google.com)”  
}

➜ ~ cat /tmp/ansibletest/myfile.txt  
Google#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;overflow-y:scroll}#gog{padding:3px 8px 0}td{line-height:.8em}.gac\_m td{line-height:17px}form{margin-bottom:20px}.h{color:#36c}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}em{font-weight:bold;font-style:normal}.lst{height:25px;width:496px}.gsfi,.lst{font:18px arial,sans-serif}.gsfs{font:17px arial,sans-serif}.ds{display:inline-box;display:inline-block;margin:3px 0 4px;margin-left:4px}input{font-family:inherit}a.gb1,a.gb2,a.gb3,a.gb4{color:#11c !important}body{background:#fff;color:black}a{color:#11c;text-decoration:none}a:hover,a:active{text-decoration:underline}.fl a{color:#36c}a:visited{color:#551a8b}a.gb1,a.gb4{text-decoration:underline}a.gb3:hover{text-decoration:none}#ghead a.gb2:hover{color:#fff !important}.sblc{padding-top:5px}.sblc a{display:block;margin:2px 0;margin-left:13px;font-size:11px}.lsbb{background:#eee;border:solid 1px;border-color:#ccc #999 #999 #ccc;height:30px}.lsbb{display:block}.ftl,#fll a{display:inline-block;margin:0 12px}.lsb{background:url(/images/srpr/nav\_logo80.png) 0 -258px repeat-x;border:none;color:#000;cursor:pointer;height:30px;margin:0;outline:0;font:15px arial,sans-serif;vertical-align:top}.lsb:active{background:#ccc}.lst:focus{outline:none}#addlang a{padding:0 3px}

 
**Search** [Images](http://www.google.com/imghp?hl=en&tab=wi) [Maps](http://maps.google.com/maps?hl=en&tab=wl) [Play](https://play.google.com/?hl=en&tab=w8) [YouTube](http://www.youtube.com/?tab=w1) [News](http://news.google.com/nwshp?hl=en&tab=wn) [Gmail](https://mail.google.com/mail/?tab=wm) [Drive](https://drive.google.com/?tab=wo) [More »](http://www.google.com/intl/en/options/)

[Web History](http://www.google.com/history/optout?hl=en) | [Settings](https://forum.ansible.com/preferences?hl=en) | [Sign in](https://accounts.google.com/ServiceLogin?hl=en&continue=http://www.google.com/)

 
 
.pmoabs{background-color:#fff;border:1px solid #E5E5E5;color:#666;font-size:13px;padding-bottom:20px;position:absolute;right:2px;top:3px;z-index:986}#pmolnk{border-radius:2px;-moz-border-radius:2px;-webkit-border-radius:2px}.kd-button-submit{border:1px solid #3079ed;background-color:#4d90fe;background-image:-webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#4787ed));background-image:-webkit-linear-gradient(top,#4d90fe,#4787ed);background-image:-moz-linear-gradient(top,#4d90fe,#4787ed);background-image:-ms-linear-gradient(top,#4d90fe,#4787ed);background-image:-o-linear-gradient(top,#4d90fe,#4787ed);background-image:linear-gradient(top,#4d90fe,#4787ed);filter:progid:DXImageTransform.Microsoft.gradient(startColorStr=‘#4d90fe’,EndColorStr=‘#4787ed’)}.kd-button-submit:hover{border:1px solid #2f5bb7;background-color:#357ae8;background-image:-webkit-gradient(linear,left top,left bottom,from(#4d90fe),to(#357ae8));background-image:-webkit-linear-gradient(top,#4d90fe,#357ae8);background-image:-moz-linear-gradient(top,#4d90fe,#357ae8);background-image:-ms-linear-gradient(top,#4d90fe,#357ae8);background-image:-o-linear-gradient(top,#4d90fe,#357ae8);background-image:linear-gradient(top,#4d90fe,#357ae8);filter:progid:DXImageTransform.Microsoft.gradient(startColorStr=‘#4d90fe’,EndColorStr=‘#357ae8’)}.kd-button-submit:active{-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);-moz-box-shadow:inset 0 1px 2px rgba(0,0,0,0.3);box-shadow:inset 0 1px 2px rgba(0,0,0,0.3)}#pmolnk a{color:#fff;display:inline-block;font-weight:bold;padding:5px 20px;text-decoration:none;white-space:nowrap}.xbtn{color:#999;cursor:pointer;font-size:23px;line-height:5px;padding-top:5px}.padi{padding:0 8px 0 10px}.padt{padding:5px 20px 0 0;color:#444}.pads{text-align:left;max-width:200px} 
 

 |   
×
  |
 | ![](https://sea1.discourse-cdn.com/ansible/images/icons/product/chrome-48.png) | A faster way to browse the web |
 |   
 [Install Google Chrome](https://forum.ansible.com/chrome/index.html?hl=en&brand=CHNG&utm_source=en-hpp&utm_medium=hpp&utm_campaign=en) 
  |
 
 

   

 ![Google](https://sea1.discourse-cdn.com/ansible/images/srpr/logo9w.png)  
  

| &nbsp; | 

  
 | [Advanced search](https://forum.ansible.com/advanced_search?hl=en&authuser=0)[Language tools](https://forum.ansible.com/language_tools?hl=en&authuser=0) |

  

[Advertising&nbsp;Programs](https://forum.ansible.com/intl/en/ads/)[Business Solutions](https://forum.ansible.com/services/)[+Google](https://plus.google.com/116899029375914044550)[About Google](https://forum.ansible.com/intl/en/about.html)

© 2013 - [Privacy & Terms](https://forum.ansible.com/intl/en/policies/)

  
`

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 29, 2014, 3:41pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/9 "2014-08-29T15:41:49Z")

</div>

It works remotely too. That was just for simplicity of testing as there’s no extra remote logic involved in the system.

Does this seem resolved for you?

---

<div class="post-metadata">

**Author:** ![Levi\_Notik](https://avatars.discourse-cdn.com/v4/letter/l/4491bb/32.png) [@Levi\_Notik](https://forum.ansible.com/u/Levi_Notik)\
**Post date:** [August 29, 2014, 8:50pm UTC](https://forum.ansible.com/t/behavior-of-get-url-if-file-exists-in-destination/16071/10 "2014-08-29T20:50:16Z")

</div>

Yes, it works now. Thanks for all your help, Michael. Really appreciate it.
