Reputation: 2008
I have a playbook like this:
- name: make a http request
shell: wget -O /dev/null http://my.site.com/some/url?with=args
The main problem is the GET Arguments. There is an "=" character that I don't know how to escape properly. If I do not escape this, ansible thinks that it's another argument for module, but if I escape it, then it make double escaping so as a result I've got "/=" in the shell.
Ansible version: 1.7.1
Thanks in advance!
Upvotes: 0
Views: 1635
Reputation: 2008
With little help the problem was found.
Problem was actually in Ansible 1.7.1. After upgrading to 1.7.2 the problem was solved.
Thanks to everyone :)
Upvotes: 1
Reputation: 24573
I wasn't able to reproduce this with a bare call to wget
. I'm using my gravatar as a URL with args. Here's a sample call.
TASK: [shell wget -O /dev/null https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24] ***
And here's the debugging output:
<hostname> REMOTE_MODULE command wget -O /dev/null https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24 #USE_SHELL
... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 1089 (1.1K) [image/jpeg]\nSaving to: `/dev/null'\n\n 0K . 100% 1.93M=0.001s\n\n2014-10-31 16:52:00 (1.93 MB/s) - `/dev/null' saved [1089/1089]", "stdout": ""}
Generally speaking, using command
, shell
, and lineinfile
are a form of code smell. In this case, it means using the get_url
module or the uri
module. wget
generally implies get_url
, but you are throwing away the output, so you are using it like curl
, which means the uri
module is better.
Here's my playbook. I needed to add pip
since httplib wasn't installed on my test host.
tasks:
- debug: var=hostvars
- pip: name=httplib2
sudo: yes
- uri: url=https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24
You can see in the verbose output that it's making the correct call.
ok: [hostname] => {"accept_ranges": "bytes", "access_control_allow_origin": "*", "cache_control": "max-age=300", "changed": false, "content_disposition": "inline; filename=\"cad260683598a6e41608b91a9b57099b.jpeg\"", "content_length": "1089", "content_location": "https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24", "content_type": "image/jpeg", "date": "Fri, 31 Oct 2014 16:58:42 GMT", "expires": "Fri, 31 Oct 2014 17:03:42 GMT", "last_modified": "Fri, 04 Nov 2011 16:27:09 GMT", "link": "<https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24>; rel=\"canonical\"", "redirected": false, "server": "ECS (ams/49F2)", "source_age": "81", "status": 200, "via": "1.1 varnish", "x_cache": "HIT", "x_varnish": "3775458975 3775177699"}
Upvotes: 0