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

标签 ansible ansible-playbook etcd

我有一个构建 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 身份在 Remote 上启动 ansible-playbook 时,“Build etcd”失败并出现错误:

failed: [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。我究竟做错了什么?

最佳答案

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

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

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

关于ansible - 尝试使用 ansible 构建包时找不到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24135722/

相关文章:

ipv4 - Ansible - 替换 ipv4 地址的主机部分

ansible - 从 ansible 变量中过滤匹配模式的子字符串并将匹配的子字符串分配给另一个变量

mysql - 为什么 zk/etcd 而不是 rdbms 用于集群协调

directory - 如何使用 Ansible 创建目录

azure - azure 的 Ansible 库存插件抛出编码错误

debugging - 在自定义 Ansible 模块中是否有调试日志记录的标准/首选方法。

yaml - 如何在同一任务中展开多个列表

command-line-arguments - 在Ansible中构建映射时发出警告

kubernetes - 带有 Vagrant 的 CoreOS 集群无法正确启动/配置 etcd

kubernetes - 如果 kube-master 或 etcd 服务宕机,Pod/Service 还能工作吗?