Skip to content

Commit

Permalink
Merge pull request #6 from fubarhouse/issue-1
Browse files Browse the repository at this point in the history
Issue 1
  • Loading branch information
fubarhouse authored Dec 22, 2016
2 parents 800eb9b + d6ad1cd commit f1fa085
Show file tree
Hide file tree
Showing 10 changed files with 592 additions and 101 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@
[![Ansible Galaxy](https://img.shields.io/badge/galaxy-fubarhouse--golang-5140.svg)](https://galaxy.ansible.com/fubarhouse/golang)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/fubarhouse/ansible-role-golang/master/LICENSE)

* Install Go to configurable locations.
* Install Go packages
* Support for custom `go get` applications.

**Note**: I am actively seeking packages to include here which are installed using `go get`. They will all feature custom installation tasks and logic.

**Note**: You may be required to restart your shell session or to source the configured `shell_profiles` prior to use after installation.
* Clean install optional - recommended if changing between static and gvm installations.
* Install a static binary of Go; or
* Install multiple versions of Go using GVM; or
* Install from Go Source.
* Installs using the Ansible way, the GVM installation script has been converted into Ansible tasks.
* Install allows additional flags to be passed in (ie --binary --prefer-binary --source)
* Install from mirror URL
* Install to any location

## Requirements

None.

## Role Variables

Installation configuration
````
go_install_type: gvm # or static
go_install_flag: "--binary"
go_custom_mirror: https://storage.googleapis.com/golang
````

Basic configuration
````
go_version: 1.7.4
go_location: /usr/local/go
````

Multiple version configuration
````
go_versions:
- 1.7.1
- 1.7.3
go_legacy_versions:
- 1.4.0
````

***OS-Specific configuration***
Expand Down
28 changes: 17 additions & 11 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
---
# defaults file for fubarhouse-golang

go_install_type: gvm
go_install_flag: "--binary"
go_custom_mirror: https://storage.googleapis.com/golang

# Go
go_version: 1.7.4
go_install_clean: false
go_version: 1.3
go_versions: []
go_legacy_versions: []
go_arch: linux-amd64
go_location: /usr/local/go
go_url: "https://storage.googleapis.com/golang/go{{ go_version }}.{{ go_arch }}.tar.gz"
go_symlink: "{{ go_location }}/bin/go"
go_url: "{{ go_custom_mirror }}/go{{ go_version }}.{{ go_arch }}.tar.gz"

# GVM-Specific variables
GVM_DEST: "{{ go_location }}"
GVM_ROOT: "{{ go_location }}"
GVM_NAME: "gvm"

# For MacOS only:
# For MacOS Static installs only:
#go_arch: debian-amd64

# Go get
Expand All @@ -19,11 +32,4 @@ gopm_packages: []

# Configuration
shell_profiles:
- .bash_profile
shell_exports:
- regex: "export GOROOT={{ go_location }}"
lineinfile: "export GOROOT={{ go_location }}"
- regex: "export GOPATH={{ go_location }}/bin"
lineinfile: "export GOPATH={{ go_location }}/bin"
- regex: export PATH=\$PATH:\$GOROOT/bin
lineinfile: export PATH=$PATH:$GOROOT/bin
- .bash_profile
69 changes: 69 additions & 0 deletions tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---

- name: "Generic | Find GOROOT"
shell: "echo $GOROOT | grep go"
register: echo_goroot
failed_when: false

- name: "Generic | Removing directories"
file:
path: "{{ item }}"
state: absent
with_items:
- "{{ echo_goroot.stdout | default(go_location) }}"
- "{{ go_location }}"
failed_when: false


- name: "Go-Lang | Define shell exports to cleanup"
set_fact:
shell_exports_static:
- regex: "export GOROOT={{ go_location }}"
lineinfile: "export GOROOT={{ go_location }}"
- regex: "export GOPATH={{ go_location }}/bin"
lineinfile: "export GOPATH={{ go_location }}/bin"
- regex: export PATH=\$PATH:\$GOROOT/bin
lineinfile: export PATH=$PATH:$GOROOT/bin
when: shell_exports_static is undefined

- name: "Go-Lang | Ensure shell profiles are clean"
become: yes
become_user: "{{ fubarhouse_user }}"
lineinfile:
dest: "{{ fubarhouse_user_dir }}/{{ item[0] }}"
regexp: "{{ item[1].regex }}"
line: "{{ item[1].lineinfile }}"
state: absent
with_nested:
- "{{ shell_profiles }}"
- "{{ shell_exports_static }}"
ignore_errors: yes
when: shell_exports_static is defined

- name: "GVM | Define shell exports to cleanup"
set_fact:
shell_exports_gvm:
- regex: "export GOROOT={{ go_location }}"
lineinfile: "export GOROOT={{ go_location }}"
- regex: "export GOPATH={{ go_location }}/bin"
lineinfile: "export GOPATH={{ go_location }}/bin"
- regex: export PATH=\$PATH:\$GOROOT/bin
lineinfile: export PATH=$PATH:$GOROOT/bin
# - regex: "{{ GVM_DEST }}/scripts/gvm"
# lineinfile: source "{{ GVM_DEST }}/scripts/gvm"
when: shell_exports_gvm is undefined

- name: "GVM | Ensure shell profiles are clean"
become: yes
become_user: "{{ fubarhouse_user }}"
lineinfile:
dest: "{{ fubarhouse_user_dir }}/{{ item[0] }}"
regexp: "{{ item[1].regex }}"
line: "{{ item[1].lineinfile }}"
state: absent
with_nested:
- "{{ shell_profiles }}"
- "{{ shell_exports_gvm }}"
ignore_errors: yes
when: shell_exports_gvm is defined

86 changes: 86 additions & 0 deletions tasks/gopm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---

- name: "GoPM | Check folder permissions/state"
become: yes
become_user: "root"
file:
path: "{{ go_location }}/modules"
state: directory
mode: 0755
owner: "{{ fubarhouse_user }}"
recurse: yes

- name: "GoPM | Run get commands for installed version"
become: yes
become_user: "{{ fubarhouse_user }}"
shell: "{{ go_symlink }} get {{ item }}"
environment:
GOPATH: "{{ go_location }}/pkg"
GOROOT: "{{ go_location }}/gos/go{{ go_version }}"
with_items: "{{ go_get }}"
when: go_version != 'master' and (go_install_type == 'gvm' or go_install_type == 'source')

- name: "GoPM | Run get commands for installed source"
become: yes
become_user: "{{ fubarhouse_user }}"
shell: "{{ go_symlink }} get -dfu {{ item }}"
environment:
GOPATH: "{{ go_location }}/pkg"
GOROOT: "{{ go_location }}/gos/{{ go_version }}"
with_items: "{{ go_get }}"
when: go_version == 'master' and (go_install_type == 'gvm' or go_install_type == 'source')

- name: "GoPM | Run get commands for static install"
become: yes
become_user: "{{ fubarhouse_user }}"
shell: "go get -dfu {{ item }}"
environment:
GOPATH: "{{ go_location }}/pkg"
GOROOT: "{{ go_location }}"
with_items: "{{ go_get }}"
when: go_install_type == 'static'

- name: "GoPM | Link installed version"
become: yes
become_user: root
file:
src: "{{ GVM_DEST }}/gos/go{{ go_version }}/bin/gopm"
dest: "{{ go_symlink }}pm"
state: link
mode: 0755
owner: "{{ fubarhouse_user }}"
force: yes
when: '"{{ go_version }}" != "master"'

- name: "GoPM | Link source version"
become: yes
become_user: root
file:
src: "{{ GVM_DEST }}/gos/{{ go_version }}/bin/gopm"
dest: "{{ go_symlink }}pm"
state: link
mode: 0755
owner: "{{ fubarhouse_user }}"
force: yes
when: '"{{ go_version }}" == "master"'

- name: "GoPM | Install packages for installed version"
become: yes
become_user: "{{ fubarhouse_user }}"
shell: "{{ go_symlink }}pm install {{ item }}"
with_items: "{{ gopm_packages }}"
when: '"github.com/gpmgo/gopm" in "{{ go_get }}" and go_version != "master" and (go_install_type == "gvm" or go_install_type == "source")'

- name: "GoPM | Install packages installed source"
become: yes
become_user: "{{ fubarhouse_user }}"
shell: "{{ go_symlink }}pm install {{ item }}"
with_items: "{{ gopm_packages }}"
when: '"github.com/gpmgo/gopm" in "{{ go_get }}" and go_version == "master" and (go_install_type == "gvm" or go_install_type == "source")'

- name: "GoPM | Install packages for static installs"
become: yes
become_user: "{{ fubarhouse_user }}"
shell: "{{ go_symlink }}pm install {{ item }}"
with_items: "{{ gopm_packages }}"
when: '"github.com/gpmgo/gopm" in "{{ go_get }}" and (go_install_type == "static")'
Loading

0 comments on commit f1fa085

Please sign in to comment.