59 lines
1.5 KiB
YAML
59 lines
1.5 KiB
YAML
- name: check go version
|
|
command: /usr/local/go/bin/go version
|
|
register: result
|
|
changed_when: no
|
|
ignore_errors: true
|
|
|
|
- name: Install Go
|
|
become: true
|
|
when: result is failed
|
|
shell: |
|
|
wget "https://go.dev/dl/go1.22.1.linux-amd64.tar.gz"
|
|
rm -rf /usr/local/go
|
|
tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz
|
|
rm -rf go1.22.1.linux-amd64.tar.gz
|
|
|
|
# - name: Install Go
|
|
# become: true
|
|
# package:
|
|
# name:
|
|
# - golang
|
|
#
|
|
#wget "https://go.dev/$(curl https://go.dev/dl/ | grep downloadBox.*linux | cut -d '"' -f 4 | cut -c2-)"
|
|
|
|
- name: Add go binary path to PATH
|
|
lineinfile:
|
|
path: "{{ ansible_user_dir }}/.profile"
|
|
insertafter: 'export PATH="$PATH.*'
|
|
line: 'export PATH="$PATH:/usr/local/go/bin:{{ ansible_user_dir }}/go/bin"'
|
|
regexp: 'export PATH="$PATH:/usr/local/go/bin:{{ ansible_user_dir }}/go/bin"'
|
|
create: true
|
|
state: present
|
|
|
|
# - name: Source profile
|
|
# shell: . "{{ ansible_user_dir }}/.profile"
|
|
|
|
- name: check go version
|
|
command: go version
|
|
register: result
|
|
changed_when: no
|
|
ignore_errors: true
|
|
|
|
- name: Print return information from the previous task
|
|
ansible.builtin.debug:
|
|
var: result
|
|
verbosity: 2
|
|
|
|
- set_fact:
|
|
go_path: "{{ lookup('env', 'GOPATH') | default(ansible_env.HOME+'/go', true) }}"
|
|
when: result is succeeded
|
|
|
|
- name: Add Go programs to PATH
|
|
lineinfile:
|
|
path: "{{ ansible_user_dir }}/.zshrc"
|
|
insertafter: 'export PATH="$PATH.*'
|
|
regexp: 'export PATH="$PATH:{{ ansible_user_dir }}/go/bin"'
|
|
line: 'export PATH="$PATH:{{ ansible_user_dir }}/go/bin"'
|
|
|
|
|