fubarhouse / ansible-role-golang

Installs the Go programming language and packages on Mac & Linux (Ubuntu, CentOS)
MIT License
105 stars 32 forks source link

go_get tries to install packages outside GOROOT #133

Closed ioncebotari closed 5 years ago

ioncebotari commented 5 years ago

I'm using this code in my main.yaml file to install Go and a few packages on a Centos 7 VM on AWS: `# Generic settings for the GO language

When installing them, I get the following error: { "changed": false, "cmd": [ "/usr/local/go/bin/go", "get", "-u", "github.com/btcsuite/btcd" ], "delta": "0:00:00.022888", "end": "2019-09-19 14:46:14.964598", "item": { "name": "btcd", "url": "github.com/btcsuite/btcd" }, "msg": "non-zero return code", "rc": 1, "start": "2019-09-19 14:46:14.941710", "stderr": "go: cannot determine module path for source directory /home/centos (outside GOPATH, no import comments)", "stderr_lines": [ "go: cannot determine module path for source directory /home/centos (outside GOPATH, no import comments)" ], "stdout": "" }

For all the three packages. How can I fix this?

fubarhouse commented 5 years ago

On the basis of this error:

go: cannot determine module path for source directory /home/centos (outside GOPATH, no import comments)

I would recommend trying to set the ansible variable GO111MODULE to "off" (please don't forget the quotes).

Looking at the packages more specifically I can see that glide and dep both don't support modules... I may be able to add package-specific module configuration in the coming days - that would allow somebody to disable module support for such cases. These ones do make sense because they are an earlier implementation of modules, so I'll make that happen regardless - it's a good move.

fubarhouse commented 5 years ago

I've got a small local prototype which adds optional configuration for GOPROXY and GO111MODULES for individual packages declared in the go get tasks - I just need to test and triage it, but it'll allow me to turn modules on by default and selectively disable modules for a given package which matches your use case in the automated tests 🙂

That's a gap I've had for a while, but I think this is an elegant solution - not everybody is adopting or will adopt modules and that is completely fair in these cases or others. It's one part of the toolchain that doesn't really need adoption by a package, as much as I would recommend it.

fubarhouse commented 5 years ago

136 Should introduce better compatibility for more flexible repository-specific configuration.

By setting the go_get item to include modules as either true or false, it will use a different installation task.

fubarhouse commented 5 years ago

137 should now allow for the following:

go_get:
  - name: btcd
    url: github.com/btcsuite/btcd
  - name: glide
    url: github.com/Masterminds/glide
    modules: false
  - name: dep
    url: github.com/golang/dep
    modules: false
ioncebotari commented 5 years ago

Thank you, @fubarhouse , for your efforts! I've tested setting the global variable "GO111MODULES" to "off" and it worked fine. Tomorrow I'll test how the fine-grained controls work for the modules

fubarhouse commented 5 years ago

I'll close this one then. If need be feel free to re-open it 🙂