我無法通過wget
的裸機重現此問題。我使用我的gravatar作爲帶args的URL。這是一個示例調用。
TASK: [shell wget -O /dev/null https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24] ***
而這裏的調試輸出:
<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": ""}
一般來說,使用command
,shell
和lineinfile
是代碼氣味的一種形式。在這種情況下,這意味着使用the get_url
module或the uri
module。 wget
一般意味着get_url
,但是您正在丟棄輸出,因此您正在使用它,如curl
,這意味着uri
模塊更好。
這是我的劇本。我需要添加pip
,因爲我的測試主機上沒有安裝httplib。
tasks:
- debug: var=hostvars
- pip: name=httplib2
sudo: yes
- uri: url=https://www.gravatar.com/avatar/cad260683598a6e41608b91a9b57099b?s=24
您可以在詳細輸出中看到它正在進行正確的調用。
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"}
http://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-in-bash-how-do-we-know-it – vaso123 2014-10-31 14:10:07
問題不在於bash轉義,問題是在轉義腳本里逃脫 – Kron 2014-10-31 14:23:56