Behavior of get_url if file exists in destination?

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

`

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 yesonly 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.

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

(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?

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).

here’s an easy thing to try:

ansible localhost -m get_url -c local -a “url=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

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

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

`
➜ ~ ansible localhost -m get_url -c local -a “url=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
}

➜ ~ 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}

.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}
×
A faster way to browse the web

Google

 

Advanced searchLanguage tools

© 2013 - Privacy & Terms

➜ ~ 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 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
}

➜ ~ cat /tmp/ansibletest/myfile.txt
change me ➜ ~ ansible localhost -m get_url -c local -a “url=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
}

➜ ~ 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}

.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}
×
A faster way to browse the web

Google

 

Advanced searchLanguage tools

© 2013 - Privacy & Terms


`

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?

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