【问题标题】:Failed to run curl command in Ansible task [duplicate]无法在 Ansible 任务中运行 curl 命令 [重复]
【发布时间】:2017-08-02 13:15:02
【问题描述】:

我有一个 ansible 任务 yml 文件来在 ubuntu 系统上安装 nodejs。

---
- name: setup nodejs
  script: curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

- name: install nodejs
  sudo: yes
  apt:
    pkg: nodejs
    state: latest

- name: install npm
  sudo: yes
  apt:
    pkg: npm
    state: latest

- name: install yarn
  sudo: yes
  apt:
    pkg: yarn
    state: latest

运行ansible-playbook时出现以下错误:

致命:[xxxx.ap-southeast-2.compute.amazonaws.com]:失败! => {"changed": false, "failed": true, "msg": "无法在预期路径中找到'curl'。"}

curl 在远程服务器的路径上可用,为什么它仍然抱怨它?

【问题讨论】:

    标签: ansible


    【解决方案1】:

    由于不推荐使用script/shell,这里是使用get_url module的方法:

    - name: Download setup_8.x script
      get_url: url=https://deb.nodesource.com/setup_8.x dest=/opt mode=755
    - name: Setup Node.js
      command: /opt/setup_8.x
    - name: Install Node.js (JavaScript run-time environment)
      apt: name=nodejs state=present
    

    【讨论】:

      【解决方案2】:

      script module 旨在运行脚本(首先从目标路径上传到目标),而不是在远程主机上执行命令。

      请阅读文档:

      path 处的本地脚本将被传输到远程节点然后执行。


      rawcommandshell 模块用于在目标上运行命令(在您的情况下,shell 是合适的,因为您使用管道)。

      【讨论】:

        【解决方案3】:

        这可能有效:

        - name: Setup Node.js
          shell: "curl -sL https://deb.nodesource.com/setup_8.x | bash -E -"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-12-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-06
          • 1970-01-01
          • 2021-08-19
          • 2017-02-23
          相关资源
          最近更新 更多