Command not found while trying to build package with ansible
Asked Answered
S

2

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?

Silveira answered 10/6, 2014 at 7:55 Comment(1)
Is the user ansible is running as and the user you test manually with the same?Schoenberg
B
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
Bax answered 10/6, 2014 at 10:49 Comment(1)
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 commandMayers
M
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
Mathia answered 13/3, 2023 at 13:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.