summaryrefslogtreecommitdiffstats
path: root/roles/go/tasks/main.yml
blob: 06f4308fa86701c83de8cc8368c8fc568309d389 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
---
- name: "Check installed go versions"
  ansible.builtin.command:
    cmd: "/usr/local/go/bin/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_facts['architecture'] == 'x86_64' else 'arm64' }}"
        go_platform: "{{ ansible_facts['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:
    path: "{{ ansible_facts['env'].HOME }}/.bashrc"
    state: "present"
    prepend_newline: true
    append_newline: true
    marker: "# ==== {mark} ANSIBLE GO CONFIG"
    block: |
      if command -v go 1>/dev/null 2>&1; then
        export PATH="$PATH:/usr/local/go/bin"
        export PATH="$HOME/go/bin:$PATH"
      fi