Skip to content

Commit

Permalink
don't download if already at required version
Browse files Browse the repository at this point in the history
  • Loading branch information
yogo1212 committed Feb 26, 2018
1 parent 18dc711 commit c501a7b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 49 deletions.
17 changes: 0 additions & 17 deletions tasks/check_signature.yml

This file was deleted.

48 changes: 48 additions & 0 deletions tasks/install_go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
- name: Setting facts based on previous autodiscovered facts
set_fact:
go_tarball_url: "{{ go_mirror }}{{ go_tarball_name }}"

- name: Fetching sha256 checksum
set_fact:
go_tarball_checksum: "sha256:{{ lookup('url',go_tarball_url+'.sha256') }}"
when: go_tarball_checksum is not defined

- name: Create download dir
file: state=directory path="{{ go_download_dir }}" mode=0755

- name: Download the Go tarball
get_url:
url: "{{ go_tarball_url }}"
dest: "{{ go_download_dir }}"
checksum: "{{ go_tarball_checksum }}"

- block:
- name: Copy Go certificate
copy:
src: linux_signing_key.pub
dest: /tmp/golang.pub

- name: Install Go certificate
command: gpg --import /tmp/golang.pub

- name: Download signature
get_url:
url: "{{ go_tarball_url }}.asc"
dest: "{{ go_download_dir }}"

- name: Verify the signature
shell: gpg --verify "{{ go_tarball_name }}.asc" "{{ go_tarball_name }}"
args:
chdir: "{{ go_download_dir }}"
when: go_check_signature

- name: Remove old installation of Go
file:
path: /usr/local/go
state: absent

- name: Extract the Go tarball
unarchive:
src: "{{ go_download_dir }}/{{ go_tarball_name }}"
dest: /usr/local
copy: no
34 changes: 2 additions & 32 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,14 @@
when:
- go_version is not defined

- name: Setting facts based on previous autodiscovered facts
set_fact:
go_tarball_url: "{{ go_mirror }}{{ go_tarball_name }}"

- name: Fetching sha256 checksum
set_fact:
go_tarball_checksum: "sha256:{{ lookup('url',go_tarball_url+'.sha256') }}"
when: go_tarball_checksum is not defined

- name: Create download dir
file: state=directory path="{{ go_download_dir }}" mode=0755

- name: Download the Go tarball
get_url:
url: "{{ go_tarball_url }}"
dest: "{{ go_download_dir }}"
checksum: "{{ go_tarball_checksum }}"

- include_tasks: check_signature.yml
when: go_check_signature

- name: Register the current Go version (if any)
command: /usr/local/go/bin/go version
ignore_errors: yes
register: current_go_version
changed_when: false

- name: Remove old installation of Go
file:
path: /usr/local/go
state: absent
when: current_go_version|failed or current_go_version.stdout != go_version_target

- name: Extract the Go tarball if Go is not yet installed or not the desired version
unarchive:
src: "{{ go_download_dir }}/{{ go_tarball_name }}"
dest: /usr/local
copy: no
- name: Install Go
include_tasks: install_go.yml
when: current_go_version|failed or current_go_version.stdout != go_version_target

- name: Add the Go bin directory to the PATH environment variable for all users
Expand Down

0 comments on commit c501a7b

Please sign in to comment.