add basic go role

This commit is contained in:
Ryan Cavicchioni 2020-01-23 07:59:32 -06:00
parent b769ea477b
commit c63271c8b5
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
5 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
go_version: 1.13.6
go_url: "https://dl.google.com/go/go{{ go_version }}.{{ ansible_system | lower }}-{{ go_arch }}.tar.gz"
go_version_str: "go version go{{ go_version }} {{ ansible_system | lower}}/{{ go_arch }}"

65
roles/go/tasks/main.yaml Normal file
View File

@ -0,0 +1,65 @@
---
- name: gather architecture specific variables
include_vars: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
files:
- "{{ ansible_userspace_architecture }}.yaml"
- "default.yaml"
paths:
- vars
- name: determine if go exists
stat:
path: /usr/local/go/bin/go
register: st
- name: determine go version
command: /usr/local/go/bin/go version
register: gv
changed_when: false
when: st.stat.exists is defined and st.stat.exists
- name: gather os specific variables
include_vars: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- vars
- name: download go
get_url:
url: "{{ go_url }}"
checksum: "{{ go_checksum }}"
dest: "/usr/local/src/go{{ go_version }}.{{ ansible_system | lower }}-{{ go_arch }}.tar.gz"
owner: root
group: root
mode: 0644
- name: remove old version of go
file:
path: /usr/local/go
state: absent
when: st.stat.exists and gv.stdout != go_version_str
- name: unpack go
unarchive:
src: "/usr/local/src/go{{ go_version }}.{{ ansible_system | lower }}-{{ go_arch }}.tar.gz"
dest: /usr/local
remote_src: yes
when: st.stat.exists is defined and not st.stat.exists
- name: environment
copy:
dest: /etc/profile.d/go.sh
owner: root
group: root
mode: 0755
content: |
PATH=$HOME/go/bin:$PATH:/usr/local/go/bin
GOPATH=$HOME/go

View File

3
roles/go/vars/i386.yaml Normal file
View File

@ -0,0 +1,3 @@
---
go_arch: 386
go_checksum: sha256:27feb013106da784f09e560720aa41ab395c67f7eed4c4a0fce04bc6e3d01c7d

View File

@ -0,0 +1,3 @@
---
go_arch: amd64
go_checksum: sha256:a1bc06deb070155c4f67c579f896a45eeda5a8fa54f35ba233304074c4abbbbd