diff --git a/data/ansible/roles/go/defaults/main.yaml b/data/ansible/roles/go/defaults/main.yaml index 233b2feca..d55f2347a 100644 --- a/data/ansible/roles/go/defaults/main.yaml +++ b/data/ansible/roles/go/defaults/main.yaml @@ -1,29 +1,7 @@ --- -# Package manager to use -package_manager: apt - -# Go version to install -golang_version: 1.20.6 - -# Expected go version output -go_version_target: "go version go{{ golang_version }} linux/amd64" - -# Set the Go workspace directory -golang_gopath: /home/{{ ansible_user }}/go - -# Set the directory to download the Go archive to -golang_download_dir: /tmp - -# Set the mirror to download Go from -golang_mirror: https://storage.googleapis.com/golang - -# Set the filename of the Go archive to download -golang_redis_filename: go{{ golang_version }}.linux-amd64.tar.gz - -# Set the Go installation directory -golang_install_dir: /usr/local/go - -# Go dependencies -go_dependencies: - - curl - - tar +go_version: "1.21.0" +go_platform: linux +go_arch: amd64 +go_tarball: go{{ go_version }}.{{ go_platform }}-{{ go_arch }}.tar.gz +go_download_url: https://dl.google.com/go/{{ go_tarball }} +go_checksum: "d0398903a16ba2232b389fb31032ddf57cac34efda306a0eebac34f0965a0742" diff --git a/data/ansible/roles/go/tasks/main.yaml b/data/ansible/roles/go/tasks/main.yaml index 6e1d4f292..1331122a9 100644 --- a/data/ansible/roles/go/tasks/main.yaml +++ b/data/ansible/roles/go/tasks/main.yaml @@ -1,56 +1,36 @@ --- -- name: Check if Go is already installed +- name: Check if Go is already installed. command: /usr/local/go/bin/go version ignore_errors: true - register: go_version_output + register: go_version_result + changed_when: false -- name: Install Go dependencies with apt - become: yes - apt: - name: '{{ go_dependencies }}' - state: present - update_cache: yes - when: package_manager == 'apt' - -- name: Install Go dependencies with dnf - become: yes - dnf: - name: '{{ go_dependencies }}' - state: present - update_cache: yes - when: package_manager == 'dnf' - -- name: Remove old installation of Go if needed - become: yes +- name: Remove current installation. file: - path: /usr/local/go state: absent - when: go_version_output.rc == 0 and go_version_output.stdout != go_version_target + path: /usr/local/go + when: + - go_version_result is succeeded + - go_version not in go_version_result.stdout -- name: Create Go language SDK installation directory - become: yes - file: - path: '{{ golang_install_dir }}' - state: directory - mode: '0755' - -- name: Download Go language SDK +- name: Download Go. get_url: - url: '{{ golang_mirror }}/{{ golang_redis_filename }}' - dest: '{{ golang_download_dir }}/{{ golang_redis_filename }}' - mode: '0644' + url: "{{ go_download_url }}" + dest: /usr/local/src/{{ go_tarball }} + checksum: "sha256:{{ go_checksum }}" + when: go_version_result is failed + or go_version not in go_version_result.stdout -- name: Install Go language SDK - become: yes +- name: Extract Go. unarchive: - src: '{{ golang_download_dir }}/{{ golang_redis_filename }}' - remote_src: true - dest: '{{ golang_install_dir | dirname }}' - creates: '{{ golang_install_dir }}/bin' + src: /usr/local/src/{{ go_tarball }} + dest: /usr/local + copy: no + when: go_version_result is failed + or go_version not in go_version_result.stdout -- name: Set Go language SDK environment variables - become: yes - template: - src: golang.sh.j2 - dest: /etc/profile.d/golang.sh - mode: '0644' +- name: Add Go to to system-wide $PATH. + copy: + dest: /etc/profile.d/go-path.sh + content: |- + export PATH=$PATH:/usr/local/go/bin diff --git a/data/ansible/roles/go/templates/golang.sh.j2 b/data/ansible/roles/go/templates/golang.sh.j2 deleted file mode 100644 index 15c38206d..000000000 --- a/data/ansible/roles/go/templates/golang.sh.j2 +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -{# Comment that describes the purpose of the template #} - -export GOROOT='{{ golang_install_dir }}' -export PATH=$PATH:$GOROOT/bin - -{% if golang_gopath %} -export GOPATH="{{ golang_gopath }}" -export PATH=$PATH:$GOPATH/bin -{% endif %}