尝试使用ansible构建包时找不到命令

时间:2014-06-10 07:55:56

标签: ansible ansible-playbook etcd

我有一个简单的ansible playbook,它构建了etcd:

- 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] => {"改变":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

第17行" build"包含以下内容:

go install github.com/coreos/etcd

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

1 个答案:

答案 0 :(得分:3)

模块joshualund.golanggo安装到非标准目录/usr/local/go(请查看sources),因此很可能是因为这个问题。

要解决此问题,您应该以某种方式更新ansible使用的$PATH变量。其中一种方法是明确指定它:

- name: Build etcd
  command: chdir={{repo_location}} ./build
  environment:
    PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin