1

I am trying to use go get which means I have to set the go path. I have tried this through a ton of ways, so please do not mark this as a duplicate unless that solution works. I have tried almost every solution on SO I could find.

My chef code

package 'golang-go'

directory '/work-disk/go' do
  owner consul_user
  group consul_user
  mode '0755'
  action :create
end

bash 'go' do
  user consul_user
  code <<-EOH
  export GOPATH=/work-disk/go
  export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
  EOH
  action :run
end

I had export GOPATH=$HOME/go before but that seemed to fail so I created a directory to test with and explicitly said the directory but still no luck

Error message

cannot download, $GOPATH not set. For more details see: go help gopath
Josh Kirby
  • 11
  • 7
  • 3
    I know nothing about chef, but what is it actually meant to run? I fail to see how exporting two variables could result in that error message. If the error comes from the NEXT statement in the recipe the explanation is simple; the variable gets exported, the shell that runs the following statement knows nothing about it. – tink Nov 17 '18 at 20:08
  • https://stackoverflow.com/q/17436535/1153938 – Vorsprung Nov 17 '18 at 21:57
  • @tink The error is from the next resource block yes, but it should not be presenting an issue as I am running both as `consul_user` so should have access to the same exports. – Josh Kirby Nov 17 '18 at 22:26

1 Answers1

1

This is not how environment variables work. Setting them in a subprocess on affects that subprocess.

coderanger
  • 52,400
  • 4
  • 52
  • 75