summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2025-09-02 19:25:26 +0200
committerAhmed Abdelhalim <[email protected]>2025-09-02 19:25:26 +0200
commitbcfbf44b501281ba9db8c6cfb0da08c169c770aa (patch)
tree66589d44a29033692382ea635fa0f443ccb2cb3d
parente1d3cc942662a132d8a86d3211857ab5e92d296e (diff)
Update the go role to handle default to latest
-rw-r--r--roles/go/defaults/main.yml6
-rw-r--r--roles/go/meta/argument_specs.yml5
-rw-r--r--roles/go/tasks/main.yml41
3 files changed, 35 insertions, 17 deletions
diff --git a/roles/go/defaults/main.yml b/roles/go/defaults/main.yml
index 9f2cae76..f28e488b 100644
--- a/roles/go/defaults/main.yml
+++ b/roles/go/defaults/main.yml
@@ -1,5 +1,3 @@
---
-go_global_version: "1.23"
-go_versions:
- - "1.21"
- - "1.23"
+go_global_version: ""
+go_versions: []
diff --git a/roles/go/meta/argument_specs.yml b/roles/go/meta/argument_specs.yml
index 4f8cebe7..f0eea1bc 100644
--- a/roles/go/meta/argument_specs.yml
+++ b/roles/go/meta/argument_specs.yml
@@ -4,9 +4,10 @@ argument_specs:
options:
go_global_version:
type: "str"
- description: "The go global version to use"
+ description: "The go global version to use (latest when empty)"
+ default: ""
go_versions:
type: "list"
- description: "The go versions to install"
+ description: "The go versions to install (latest when empty)"
elements: "str"
default: []
diff --git a/roles/go/tasks/main.yml b/roles/go/tasks/main.yml
index 27515584..52854f8f 100644
--- a/roles/go/tasks/main.yml
+++ b/roles/go/tasks/main.yml
@@ -11,15 +11,34 @@
export PATH="$HOME/go/bin:$PATH"
fi
-- name: "Instal Go versions"
- community.general.homebrew:
- name:
- - "go@{{ item }}"
- with_items: "{{ 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 global go version"
- ansible.builtin.command:
- cmd: "brew link go@{{ go_global_version }}"
- environment:
- PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
- changed_when: false
+ - name: "Set latest Go as global version"
+ ansible.builtin.command:
+ cmd: "brew link --force go"
+ environment:
+ PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
+ changed_when: true
+
+- name: "Install and configure 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: "Set specific Go version as global"
+ ansible.builtin.command:
+ cmd: "brew link --force go@{{ go_global_version }}"
+ environment:
+ PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}"
+ when: go_global_version != ""
+ changed_when: true