forked from bitlair/ansible
66 lines
1.8 KiB
YAML
66 lines
1.8 KiB
YAML
---
|
|
- name: go
|
|
tags: go,go_install
|
|
block:
|
|
- name: Remove Debian Go package
|
|
ansible.builtin.apt:
|
|
name: golang
|
|
autoremove: yes
|
|
state: absent
|
|
|
|
- name: Install dependencies
|
|
ansible.builtin.apt:
|
|
name: curl
|
|
state: present
|
|
|
|
- name: Fetch Go latest version
|
|
ansible.builtin.shell: "curl --silent --location https://go.dev/dl/ | grep -Eo 'go[0-9]+(\\.[0-9]+)+.linux' | sort -V | uniq | tail -1 | sed s/^go// | sed s/\\.linux$//"
|
|
changed_when: false
|
|
register: go_latest_version_shell
|
|
|
|
- name: Format Go latest version variable
|
|
set_fact:
|
|
go_latest_version: "{{ go_latest_version_shell.stdout }}"
|
|
|
|
- name: Detect installed Go version
|
|
shell: "go version | grep --color=never -Po '\\d\\.\\d+(\\.\\d+)?' || echo none"
|
|
register: go_installed_version_shell
|
|
changed_when: false
|
|
|
|
- name: Format Go version variable
|
|
set_fact:
|
|
go_installed_version: "{{ go_installed_version_shell.stdout }}"
|
|
|
|
- debug:
|
|
msg:
|
|
- "Latest Go version: {{ go_latest_version}}"
|
|
- "Installed Go version: {{ go_installed_version }}"
|
|
|
|
- name: Remove installed go
|
|
file:
|
|
state: absent
|
|
path: /usr/local/go
|
|
when: go_installed_version != go_latest_version
|
|
|
|
- name: Install Go
|
|
unarchive:
|
|
src: https://go.dev/dl/go{{ go_latest_version }}.linux-{{ go_arch }}.tar.gz
|
|
dest: /usr/local
|
|
remote_src: yes
|
|
owner: root
|
|
group: root
|
|
when: go_installed_version != go_latest_version
|
|
|
|
- name: Configure Go environment
|
|
template:
|
|
src: go.profile
|
|
dest: /etc/profile.d/go.sh
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
|
|
- name: Link go binary
|
|
file:
|
|
state: link
|
|
src: /usr/local/go/bin/go
|
|
dest: /usr/local/bin/go
|