diff options
| author | Ahmed Abdelhalim <[email protected]> | 2025-10-19 23:01:00 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2025-10-20 00:39:02 +0200 |
| commit | cf400c3e738f9660cc76e9fad82c4654acca2583 (patch) | |
| tree | ae41e8c24a6b7604f0d3570e58cc2291449f1124 /roles/go/tasks | |
| parent | 54d644bab1ef9cd8663d3366b1b3c94f57f5b945 (diff) | |
Refactor go role to install 1 version and remove homebrew dependency
Diffstat (limited to 'roles/go/tasks')
| -rw-r--r-- | roles/go/tasks/main.yml | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/roles/go/tasks/main.yml b/roles/go/tasks/main.yml index 6c4f08c8..69c552bf 100644 --- a/roles/go/tasks/main.yml +++ b/roles/go/tasks/main.yml @@ -1,8 +1,31 @@ --- -- name: "Install latest Go via Homebrew" - community.general.homebrew: - name: "go" - state: "present" +- name: "Check installed go versions" + ansible.builtin.command: + cmd: "go version" + register: go_installed_version + changed_when: false + failed_when: false + +- name: "Install go" + when: go_version not in go_installed_version.stdout + block: + - name: "Set go facts" + ansible.builtin.set_fact: + go_arch: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'arm64' }}" + go_platform: "{{ ansible_system | lower }}" + + - name: "Download Go" + ansible.builtin.get_url: + url: "https://dl.google.com/go/go{{ go_version }}.{{ go_platform }}-{{ go_arch }}.tar.gz" + dest: "/tmp/go.tar.gz" + mode: "0644" + + - name: "Unarchive Go" + become: true + ansible.builtin.unarchive: + src: "/tmp/go.tar.gz" + dest: "/usr/local" + remote_src: true - name: "Add Go to shell profile" ansible.builtin.blockinfile: @@ -13,26 +36,6 @@ marker: "# ==== {mark} ANSIBLE GO CONFIG" block: | if command -v go 1>/dev/null 2>&1; then - export PATH="$HOME/go/bin:$PATH" - export PATH="$HOME/sdk/*/bin:$PATH" + export PATH="$PATH:/usr/local/go/bin" + export PATH="$HOME/go/bin:$PATH" fi - -- name: "Install Go version managers" - ansible.builtin.command: - cmd: "go install golang.org/dl/go{{ item }}@latest" - args: - creates: "{{ ansible_env.HOME }}/go/bin/go{{ item }}" - environment: - PATH: "/home/linuxbrew/.linuxbrew/bin:{{ ansible_env.PATH }}" - loop: "{{ go_versions }}" - when: go_versions | length > 0 - -- 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 }}" - loop: "{{ go_versions }}" - when: go_versions | length > 0 |
