diff --git a/tasks/check_signature.yml b/tasks/check_signature.yml deleted file mode 100644 index 20ce285..0000000 --- a/tasks/check_signature.yml +++ /dev/null @@ -1,17 +0,0 @@ -- 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 }}" \ No newline at end of file diff --git a/tasks/install_go.yml b/tasks/install_go.yml new file mode 100644 index 0000000..0c409c8 --- /dev/null +++ b/tasks/install_go.yml @@ -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 \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index e53aa2b..2c7195d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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