【问题标题】:Cannot run CURL command in Ansible无法在 Ansible 中运行 CURL 命令
【发布时间】:2019-11-20 06:09:40
【问题描述】:

我尝试使用 ansible 下载 Istio。在那里我使用了以下结构。

- name: Download Istio
  command: curl https://istio.io/downloadIstio | sh -
- name: Start minikube
  command: minikube start

但是当我运行它返回的命令时,

fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["curl", "https://istio.io/downloadIstio", "|", "sh", "-"], "delta": "0:00:00.005276", "end": "2019-11-20 11:32:17.749051", "msg": "non-zero return code", "rc": 2, "start": "2019-11-20 11:32:17.743775", "stderr": "curl: option -: is unknown\ncurl: try 'curl --help' or 'curl --manual' for more information", "stderr_lines": ["curl: option -: is unknown", "curl: try 'curl --help' or 'curl --manual' for more information"], "stdout": "", "stdout_lines": []}

如何解决这个问题?

【问题讨论】:

    标签: macos curl ansible istio


    【解决方案1】:

    来自the documentation of the "command" module

    命令不会通过 shell 处理,所以变量 像 $HOME 和像“”、“|”、“;”这样的操作而“&”不会 工作。如果您需要这些功能,请使用 shell 模块。

    改为使用"shell" module

    - name: Download Istio
      shell: curl https://istio.io/downloadIstio | sh -
    

    【讨论】:

    • 除此之外,在这种简单的情况下(获取远程内容),不要在 shell 中使用 curl,使用 get_urluri 模块
    【解决方案2】:

    根据 ansible docs 和 Zeitounator comment

    命令模块不支持扩展的 shell 语法,如管道和重定向(尽管 shell 变量将始终有效)。如果您的命令需要特定于 shell 的语法,请改用 shell 模块。

    请考虑使用get_url module

    从 HTTP、HTTPS 或 FTP 下载文件到远程服务器。远程服务器必须能够直接访问远程资源。 您可以将其与 shell 模块结合使用:

    作为示例,请查看此community example

    - name: Download zsh installer
        get_url: url=https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh dest=/tmp/zsh-installer.sh
    
      - name: Execute the zsh-installer.sh
        shell: /tmp/zsh-installer.sh
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 1970-01-01
      • 2021-10-26
      • 2016-04-06
      • 1970-01-01
      • 2016-06-22
      相关资源
      最近更新 更多