【问题标题】:How to use curl command in ansible playbook如何在 ansible playbook 中使用 curl 命令
【发布时间】:2019-06-11 04:49:34
【问题描述】:

我必须在 playook 中编写与此 curl 中给出的相同的语法 - curl -Is "{{url}}" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE 'Set-Cookie:|Location'

我必须在 playook 中编写与此 curl 中给出的相同的语法 - curl -Is "{{url}}" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE 'Set-Cookie:|Location'

- name: "sanity"
  shell: curl -Is "https://{{ENV_DOMAIN}}/applicationNavigator/" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE
  args:
     warn: no
  register: res
- debug:
    var: res

错误!加载 YAML 时出现语法错误。 在此上下文中不允许映射值

错误似乎在“/mnt/banner/deploy/ansible/sanity_test_update.yml”中:第 40 行,第 84 列,但可能 根据确切的语法问题,位于文件的其他位置。

违规行似乎是:

    - name: "sanity"
      shell: curl -Is "https://studentconnect.acu.edu.au/BannerAdmin.ws/" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE
                                                                                   ^ here
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes. If starting a value with a quote, make sure the
line ends with the same set of quotes. For instance this arbitrary
example:

    foo: "bad" "wolf"

Could be written as:

    foo: '"bad" "wolf"'

【问题讨论】:

  • 如果我从本地运行 cURL 命令 [curl -Is "studentconnect.acu.edu.au/BannerAdmin.ws" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE 'Set-Cookie:|Location']命令提示其给出结果如下- curl -Is "studentconnect.acu.edu.au/BannerAdmin.ws" -H "Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1"|grep -iE 'Set-Cookie:|Location' 我在剧本中尝试使用 -command : curl -Is "studentconnect.acu.edu.au/BannerAdmin.ws" -H "Cookie:ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1 它的nt工作
  • 低于错误-致命:[localhost]:失败! => {“更改”:真,“cmd”:[“curl”,“-Is”,“studentconnect.acu.edu.au/BannerAdmin.ws”,“-H”,“Cookie:ROUTEID=8d1617097a 0a51a9e361709ad3f5254b;isBannerTester=1”],“delta ": "0:00:21.349820", "end": "2019-06-11 19:49:15.116093", "msg": "非零返回码", "rc": 7, "start": " 2019-06-11 19:48:53.766273", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
  • 似乎我的脚本现在正在运行,但有时它会出错,有时它会起作用,我怀疑它的超时问题。任何人都可以帮助获取超时语法,下面是我的脚本---任务:-名称:cURL 命令外壳:curl -Is "studentconnect.acu.edu.au/BannerAdmin.ws" -H "Cookie:ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1" args: warn :没有注册:res - 调试:var:res.stdout_lines

标签: curl ansible


【解决方案1】:

试试ansible中的uri模块。

- name: curlcommand
  uri:
    url: https://studentconnect.acu.edu.au/BannerAdmin.ws/
    headers:
      Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b
      isBannerTester=1

您甚至可以通过提供 status code: 200 或任何您想要的代码来检查特定的状态代码。

【讨论】:

【解决方案2】:

试试foo: '"bad" "wolf"' 的建议。我认为应该转义引用。

shell: 'curl -Is \"https://{{ENV_DOMAIN}}/applicationNavigator/\"
             -H \"Cookie: ROUTEID=8d1617097a0a51a9e361709ad3f5254b; isBannerTester=1\"|
        grep -iE'

【讨论】:

  • 最好把这些cmets放到问题里。您可以编辑和更新问题。
猜你喜欢
  • 2018-02-06
  • 1970-01-01
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 2016-06-18
  • 2019-11-21
  • 1970-01-01
  • 2013-12-09
相关资源
最近更新 更多