community.general.golang_package module – Manage Go packages with go install
Note
This module is part of the community.general collection (version 13.1.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.golang_package.
New in community.general 13.1.0
Synopsis
Manage Go packages with
go install.Packages are installed as binaries into the Go binary directory (
GOBIN).Uninstalling a package removes its binary from
GOBIN.
Requirements
The below requirements are needed on the host that executes this module.
Go >= 1.16
Parameters
Parameter |
Comments |
|---|---|
Path to the If not specified, the module looks for |
|
The name of a Go package to install. Must be a full Go package path, for example A version can be specified inline using the The inline |
|
The desired state of the Go package. Choices:
|
|
The version to install, for example The version must include the Can only be used when When not specified and |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Support: full |
Can run in |
|
Support: none |
Returns details on what has changed (or possibly needs changing in |
Notes
Note
The Go binary directory is determined by
go env GOBIN. To customize the install location, set theGOBINenvironment variable using the task’senvironmentdirective.Go does not provide a native uninstall command. When
state=absent, the module removes the binary file fromGOBINdirectly.
Examples
- name: Install stringer
community.general.golang_package:
name: golang.org/x/tools/cmd/stringer
- name: Install golangci-lint at a specific version
community.general.golang_package:
name: github.com/golangci/golangci-lint/cmd/golangci-lint
version: v1.55.2
- name: Install multiple packages at specific versions
community.general.golang_package:
name:
- golang.org/x/tools/cmd/stringer@v0.29.0
- github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
- name: Install multiple packages
community.general.golang_package:
name:
- golang.org/x/tools/cmd/stringer
- golang.org/x/tools/cmd/goimports
- name: Remove stringer
community.general.golang_package:
name: golang.org/x/tools/cmd/stringer
state: absent
- name: Update golangci-lint to the latest version
community.general.golang_package:
name: github.com/golangci/golangci-lint/cmd/golangci-lint
state: latest
- name: Install into a custom directory
community.general.golang_package:
name: golang.org/x/tools/cmd/stringer
environment:
GOBIN: /usr/local/bin