如何在ansible剧本中逃避'='字符

时间:2014-10-31 14:07:02

标签: escaping ansible ansible-playbook

我有这样的剧本:

- name: make a http request
  shell: wget -O /dev/null http://my.site.com/some/url?with=args

主要问题是GET参数。有一个" ="我不知道如何正确逃脱的角色。 如果我不逃避这一点,ansible认为这是模块的另一个论点,但如果我逃避它,那么它会进行双重转义,因此我得到了#34; / =&#34 ;在shell中。

Ansible版本:1.7.1

提前致谢!

2 个答案:

答案 0 :(得分:1)

在没有帮助的情况下找到了问题。

问题实际上在Ansible 1.7.1中。升级到1.7.2后问题解决了。

感谢大家:)

答案 1 :(得分:0)

我无法通过拨打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": ""}

一般来说,使用commandshelllineinfile是代码嗅觉的一种形式。在这种情况下,这意味着使用the get_url modulethe uri modulewget通常暗示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"}
相关问题