5

I have a simple ansible playbook which builds 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

So when I launch ansible-playbook on the remote as root "Build etcd" fails with error:

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

17th line in "build" contains the following:

go install github.com/coreos/etcd

But go is installed and I can build etcd manually on the remote server. What am I doing wrong?

2 Answers2

9

Module joshualund.golang installs go to non-standart directory /usr/local/go (look at the sources) so a problem most likely because of this fact.

To resolve it you should somehow update $PATH variable which used by ansible. One of the way is to explicitly specify it:

- name: Build etcd
  command: chdir={{repo_location}} ./build
  environment:
    PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin
Slava Semushin
  • 14,904
  • 7
  • 53
  • 69
  • This also helped me, thank you! A note for anyone else looking at this, I created an EC2 AMI with go already installed and could ssh into the instance and run `go` successfully but ansible still failed even though the user was specified the same. I printed the `$PATH` to a file and noticed that the path for my ansible user was different(?). I ended up using the full path of the go binary in my ansible command – ddrake12 Nov 30 '17 at 23:28
0

Another way out here was to reference the binary using absolute path For Ex: while calling go binaries I provided absolute path knowing exactly where they'd be stored which $HOME/go/bin by default if you install go-lang using apt.

# Go binaries need to be provided full path
  - name: Update Nuclei Templates
    shell: "/home/ubuntu/go/bin/nuclei -ut"
    args:
      executable: /bin/bash
Rohit Salecha
  • 893
  • 11
  • 9