0

Writing my first Ansible Script. I am trying to install GVM.

I install GVM ok (I logged into the box and checked) when I run gvm version on the box direct I get: Go Version Manager v1.0.22 installed at /d1/golang/gvm

But when I run it as a command in Ansible:

- name: GVM Version
  shell: gvm version
  become: yes

I get the following error:

failed: [prod2] => {"changed": true, "cmd": "gvm version", "delta": "0:00:00.002081", "end": "2015-10-19 13:41:54.123575", "rc": 127, "start": "2015-10-19 13:41:54.121494", "warnings": []}
stderr: /bin/bash: gvm: command not found

FATAL: all hosts have already failed -- aborting

I am running a bash script which contains: source /d1/golang/gvm/scripts/gvm which is supposed to ensure you don't have to restart the terminal - see ansible command below.

- name: Run gvm source
  shell: . /etc/profile.d/golang.sh executable=/bin/bash
  become: yes

Any ideas what I am doing wrong?

Elliot Reeve
  • 901
  • 4
  • 21
  • 39
  • When are you sourcing the gvm environment? Your ansible task is only calling 'gvm'. – JimB Oct 19 '15 at 13:51
  • @JimB I have updated the main question with reference to the sourcing. – Elliot Reeve Oct 19 '15 at 13:55
  • 3
    Ansible tasks are run independently. Changing the environment in one shell doesn't affect another. You need to install gvm in a manner that you can call it directly with the correct environment. If it's just a PATH problem, use the full path. – JimB Oct 19 '15 at 13:58

1 Answers1

0

I ended up running two commands in the ansible command

name: Install go
  shell: . /etc/profile.d/golang.sh && gvm install go1.5 executable=/bin/bash

This ensures the source has been set then allows the gvm command to be run.

Elliot Reeve
  • 901
  • 4
  • 21
  • 39