summaryrefslogtreecommitdiffstats
path: root/roles/go
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-09-15 18:03:02 +0200
committerAhmed Abdelhalim <[email protected]>2025-09-15 18:03:02 +0200
commit3995eead6f1e79353547c8437ec2586adf7fd055 (patch)
tree1cd83658e7f0d9b9aaff62a2e9cc23e94c79f066 /roles/go
parent4d7ca7973fb04abd73e800531c126a4c47b50379 (diff)
Refactor go role to simplify version management
Diffstat (limited to 'roles/go')
-rw-r--r--roles/go/defaults/main.yml1
-rw-r--r--roles/go/meta/argument_specs.yml6
-rw-r--r--roles/go/tasks/main.yml80
3 files changed, 23 insertions, 64 deletions
diff --git a/roles/go/defaults/main.yml b/roles/go/defaults/main.yml
index f28e488b..0e0a3176 100644
--- a/roles/go/defaults/main.yml
+++ b/roles/go/defaults/main.yml
@@ -1,3 +1,2 @@
---
-go_global_version: ""
go_versions: []
diff --git a/roles/go/meta/argument_specs.yml b/roles/go/meta/argument_specs.yml
index 9468a5cd..03ef8608 100644
--- a/roles/go/meta/argument_specs.yml
+++ b/roles/go/meta/argument_specs.yml
@@ -4,12 +4,8 @@ argument_specs:
short_description: "Install Go (versions) on Linux distributions"
description: "Install Go (versions) on Linux distributions"
options:
- go_global_version:
- type: "str"
- description: "The go global version to use (latest when empty)"
- default: ""
go_versions:
type: "list"
- description: "The go versions to install (latest when empty)"
+ description: "The extra go versions to install (latest is used as version manager)"
elements: "str"
default: []
diff --git a/roles/go/tasks/main.yml b/roles/go/tasks/main.yml
index 84ade883..13612f29 100644
--- a/roles/go/tasks/main.yml
+++ b/roles/go/tasks/main.yml
@@ -1,4 +1,9 @@
---
+- name: "Install latest Go via Homebrew"
+ community.general.homebrew:
+ name: "go"
+ state: "present"
+
- name: "Add Go to shell profile"
ansible.builtin.blockinfile:
path: "{{ ansible_env.HOME }}/.bashrc"
@@ -9,66 +14,25 @@
block: |
if command -v go 1>/dev/null 2>&1; then
export PATH="$HOME/go/bin:$PATH"
+ export PATH="$HOME/sdk/*/bin:$PATH"
fi
-- name: "Get installed Go versions"
- ansible.builtin.shell: |
- set -o pipefail
- /home/linuxbrew/.linuxbrew/bin/brew list | grep '^go@' | sed 's/go@//'
+- name: "Install Go version managers"
+ ansible.builtin.command:
+ cmd: "go install golang.org/dl/go{{ item }}@latest"
args:
- executable: /bin/bash
- register: go_installed_versions
- changed_when: false
- failed_when: false
-
-- name: "Remove unwanted Go versions"
- community.general.homebrew:
- name: "go@{{ item }}"
- state: "absent"
- with_items: "{{ go_installed_versions.stdout_lines | default([]) }}"
- when:
- - go_installed_versions.rc == 0
- - item not in go_versions
-
-- name: "Install and configure Go latest"
- when: go_versions | length == 0
- block:
- - name: "Install latest Go"
- community.general.homebrew:
- name: "go"
- state: "present"
-
- - name: "Set latest Go as global version"
- community.general.homebrew:
- name: "go"
- state: "linked"
- # The set global version always run and is always changing the system
- # It's intentional to ignore this task for idempotency test
- tags:
- - molecule-idempotence-notest
-
-- name: "Install and configure Go versions"
+ creates: "{{ ansible_env.HOME }}/go/bin/go{{ item }}"
+ environment:
+ PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
+ with_items: "{{ go_versions }}"
when: go_versions | length > 0
- block:
- - name: "Install specific Go versions"
- community.general.homebrew:
- name: "go@{{ item }}"
- state: "present"
- with_items: "{{ go_versions }}"
-
- - name: "Unlink existing Go package"
- community.general.homebrew:
- name: "go"
- state: "unlinked"
- when: go_global_version != ""
- failed_when: false
- - name: "Set specific Go version as global"
- community.general.homebrew:
- name: "go@{{ go_global_version }}"
- state: "linked"
- when: go_global_version != ""
- # The set global version always run and is always changing the system
- # It's intentional to ignore this task for idempotency test
- tags:
- - molecule-idempotence-notest
+- name: "Download and install Go versions"
+ ansible.builtin.command:
+ cmd: "{{ ansible_env.HOME }}/go/bin/go{{ item }} download"
+ args:
+ creates: "{{ ansible_env.HOME }}/sdk/go{{ item }}/bin/go"
+ environment:
+ PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
+ with_items: "{{ go_versions }}"
+ when: go_versions | length > 0