无法在Ansible任务中运行curl命令

时间:2017-08-02 13:15:03

标签: ansible

我已经打开了ansible task 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]:失败了! => {"更改":false,"失败":true," msg":"无法找到' curl'在预期的路径中。"}

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

3 个答案:

答案 0 :(得分:1)

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

请阅读文档:

  

路径中的本地脚本将被传输到远程节点,然后执行。

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

答案 1 :(得分:0)

这可能有效:

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

答案 2 :(得分:0)

由于不建议使用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
相关问题