# Spaces in URL and file name with get\_url and unarchive

**URL:** <https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728>\
**Category:** Ansible Project\
**Created:** [November 10, 2015, 4:31pm UTC](https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728 "2015-11-10T16:31:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Sowatskey](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@Nathan\_Sowatskey](https://forum.ansible.com/u/Nathan_Sowatskey)\
**Post date:** [November 10, 2015, 4:31pm UTC](https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728/1 "2015-11-10T16:31:11Z")

</div>

Hi

This URL is for the PyDev plugin for Eclipse:

[http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev) 4.4.0/PyDev 4.4.0.zip

Note that there is a space in the URL and in the file name itself.

Those spaces mean that the get\_url plugin, at least on CentOS 7, does not work for me.

Note that using a shell command with wget does work, with the same variables, that make up the URL and file name, I am using with the get\_url plugin.

Further, the space in the file name means that the unarchive plugin does not work, at least on CentOS 7.

This latter issue has started occurring in the last week or so.

Note that using a command with unzip does not work either

Has anyone else see anything like this?

Many thanks

Nathan

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 11, 2015, 2:33pm UTC](https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728/2 "2015-11-11T14:33:02Z")

</div>

Could you give some more information? Which version of ansible? What error message? The talk from your playbook that’s failing?

Thanks,  
Toshio

---

<div class="post-metadata">

**Author:** ![Nathan\_Sowatskey](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@Nathan\_Sowatskey](https://forum.ansible.com/u/Nathan_Sowatskey)\
**Post date:** [November 17, 2015, 1:13pm UTC](https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728/3 "2015-11-17T13:13:31Z")

</div>

Hi Toshio

Apologies for the lack of detail, and thanks for following up. The Ansible version is 1.9.4.

The playbook in question is here:

[https://github.com/DevOps4Networks/ansible-eclipse](https://github.com/DevOps4Networks/ansible-eclipse)

See this section at line 207 of tasks/eclipse.yml:

- name: eclipse | Get eclipse Pydev plugin bundle

#TODO Test get\_url again and raise a bug about spaces in the URL

#shell: mkdir -p /tmp/pydev; cd /tmp/pydev; wget “{{ pydev\_url }}/{{ pydev\_bundle }}” -O pydev.zip

get\_url: url=“{{ pydev\_url }}/{{ pydev\_bundle }}” dest=/tmp/pydev

when: eclipse\_plugins\_pydev\_enabled and eclipse\_plugins\_enabled

What I see with the get\_url as shown above is :

failed: [localhost] =\> {“dest”: “/tmp/pydev”, “failed”: true, “response”: “HTTP Error 404: Not Found”, “state”: “absent”, “status\_code”: 404, “url”: “[http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev) 4.4.0/PyDev 4.4.0.zip”}

When I comment out the get\_url, and instead use the shell command, I get:

virtualbox-iso: REMOTE\_MODULE command mkdir -p /tmp/pydev; cd /tmp/pydev; wget “[http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev) 4.4.0/PyDev 4.4.0.zip” -O pydev.zip #USE\_SHELL  
virtualbox-iso: EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1447762454.08-148319008390996 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1447762454.08-148319008390996 && echo $HOME/.ansible/tmp/ansible-tmp-1447762454.08-148319008390996’]  
virtualbox-iso: PUT /tmp/tmpVCp9bn TO /home/vagrant/.ansible/tmp/ansible-tmp-1447762454.08-148319008390996/command  
virtualbox-iso: EXEC /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=tkmorsunmtemcrgbveavrpuzchnbshbv] password: " -u root /bin/sh -c '”’“‘echo BECOME-SUCCESS-tkmorsunmtemcrgbveavrpuzchnbshbv; LANG=C LC\_CTYPE=C /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1447762454.08-148319008390996/command; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1447762454.08-148319008390996/ \>/dev/null 2\>&1’”‘"’’  
virtualbox-iso: changed: [localhost] =\> {“changed”: true, “cmd”: “mkdir -p /tmp/pydev; cd /tmp/pydev; wget "[http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev) 4.4.0/PyDev 4.4.0.zip" -O pydev.zip”, “delta”: “0:00:04.525719”, “end”: “2015-11-17 12:14:18.683421”, “rc”: 0, “start”: “2015-11-17 12:14:14.157702”, “stderr”: "–2015-11-17 12:14:14-- [http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev%204.4.0/PyDev%204.4.0.zip\nResolving](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev%204.4.0/PyDev%204.4.0.zip%5CnResolving) [freefr.dl.sourceforge.net](http://freefr.dl.sourceforge.net) ([freefr.dl.sourceforge.net](http://freefr.dl.sourceforge.net))… 88.191.250.136, 2a01:e0d:1:8:58bf:fa88:0:1\nConnecting to [freefr.dl.sourceforge.net](http://freefr.dl.sourceforge.net) ([freefr.dl.sourceforge.net](http://freefr.dl.sourceforge.net))|88.191.250.136|:80… connected.\nHTTP request sent, awaiting response… 200 OK\nLength: 20099782 (19M) [application/octet-stream]\nSaving to: ‘pydev.zip’\n\n 0K … … … … … 0% 268K 73s\n 50K … … … … … 0% 669K 51s\n 100K … … … … … 0% 12.7M 34s\n 150K … … … … … 1% 1.36M 29s\n 200K … … … … …

Which is to day that it works.

I tested the unarchive issue again with a space in the file name, and I can’t reproduce the issue for now. I’ll look out for it though.

Regards

Nathan

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [November 17, 2015, 7:56pm UTC](https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728/4 "2015-11-17T19:56:29Z")

</div>

tldr; url escape your url string, replace the spaces with %20, and it  
will work. You can use the urlencode jinja2 filter if you like but it  
will change how you store the elements of your url slightly:

- vars:  
&nbsp;&nbsp;&nbsp;&nbsp;pydev\_url\_scheme: http  
&nbsp;&nbsp;&nbsp;&nbsp;pydev\_url: freefr.dl.sourceforge.net/project/pydev/pydev/PyDev 4.4.0/  
&nbsp;&nbsp;&nbsp;&nbsp;pydev\_bundle: PyDev 4.4.0.zip  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- get\_url: url="{{pydev\_url\_scheme}}://{{ pydev\_url

> urlencode()}}/{{ pydev\_bundle|urlencode() }}" dest=/tmp/pydev

In depth:

I can duplicate and the problem would be solved by doing a  
urllib.quote of the path element of the url string(which replaces  
spaces with "%20") .... Not sure whether we should do that or not. It  
would be a change in behaviour that breaks things for people who  
already escape their url. In my experience, tools commonly accept  
spaces and escape if they are not already escaped. Libraries commonly  
force the user to escape themselves.

Experimenting shows that curl does not automatically escape spaces  
(although its interaction with this server is somewhat surprising...  
it's returning a 302 to a page saying the mirror failed rather than a  
404). Manually changing the spaces to %20 is required.

Looks like wget attempts to be smart. I haven't worked out the exact  
algorithm it's using but it seems to automatically escape spaces. It  
escaped a percent not followed by a number. But it did not escape a  
percent followed by a number. So with wget, both  
"[http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev) 4.4.0/"  
and "[http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev%204.4.0/&quot](http://freefr.dl.sourceforge.net/project/pydev/pydev/PyDev%204.4.0/&quot);  
work but if you have a file named ugly%42file.html, the url you'd have  
to create for that would have to manually escape the percent sign like  
this: ugly%2542file.html.

So for ansible... we could take a few different paths i think:  
\* Do nothing -- we match curl's behaviour here. People can just use %  
escaping for the urls they specify and the jinja iflter helps with  
that.  
\* Do something like wget and escape spaces and certain uses of  
percents. This will break backwards compat but probably for only a  
few people.  
\* Add a parameter to get\_url to let the user specify whether we should  
escape or not defaulting to no escape. this is fully backwards  
compatible and lets the user choose whether to escape or not.

Willing to hear some discussion and a pull request to implement a  
change based on that.

-Toshio

---

<div class="post-metadata">

**Author:** ![Nathan\_Sowatskey](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@Nathan\_Sowatskey](https://forum.ansible.com/u/Nathan_Sowatskey)\
**Post date:** [November 18, 2015, 9:34am UTC](https://forum.ansible.com/t/spaces-in-url-and-file-name-with-get-url-and-unarchive/19728/5 "2015-11-18T09:34:23Z")

</div>

Toshio

This is very helpful, thank you very much.

My vote is for is an option that turns it on explicitly.

My reasoning is as follows:

- That would obviate the need to change variable values explicitly, which may anyway not be possible if the variable value is external and not under the control or definition of the playbook, e.g. an environment variable or a variable generated by another system at runtime.  
- It would support “intelligent” behaviour, and it is reasonable to expect tools such as Ansible to be intelligent and do such things for you.  
- I find the current behaviour and the lack of an option surprising, obviously, so there is an element of failing to pass the test of “least surprise”.

Regards

Nathan
