4

我有一个构建 etcd 的简单 ansible 剧本:

- hosts: all

  vars:
    repo_location: /var/lib/etcd/src/

  roles:
    - joshualund.golang
    #to install go

  tasks:
    - name: Clone etcd
      action: git repo=https://github.com/coreos/etcd dest={{repo_location}}

    - name: Build etcd
      command: chdir={{repo_location}} ./build

    - name: Start etcd
      service: ./bin/etcd state=started

因此,当我以 root 身份在遥控器上启动 ansible-playbook 时,“Build etcd”失败并出现错误:

失败:[test] => {"changed": true, "cmd": ["./build"], "delta": "0:00:00.002628", "end": "2014-06-10 07: 44:23.952227", "rc": 127, "start": "2014-06-10 07:44:23.949599"} stderr: ./build: 17: ./build: go: not found

“build”中的第 17 行包含以下内容:

go install github.com/coreos/etcd

但是安装了 go,我可以在远程服务器上手动构建 etcd。我究竟做错了什么?

4

1 回答 1

7

模块joshualund.golang安装go到非标准目录/usr/local/go(查看源代码)所以很可能是因为这个事实而出现问题。

要解决它,您应该以某种方式更新$PATHansible 使用的变量。一种方法是明确指定它:

- name: Build etcd
  command: chdir={{repo_location}} ./build
  environment:
    PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin
于 2014-06-10T10:49:48.663 回答