From adb9161079de2044c1a01ed05a02a21904e6c5ae Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Fri, 24 Jan 2025 17:21:41 -0700 Subject: [PATCH] install go only if version is different from desired --- tasks/build/go.yml | 109 ++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 50 deletions(-) diff --git a/tasks/build/go.yml b/tasks/build/go.yml index f1e03be..277cd91 100644 --- a/tasks/build/go.yml +++ b/tasks/build/go.yml @@ -3,54 +3,63 @@ file: go.yml name: _go -- name: set go arch - ansible.builtin.set_fact: - arch: "{{ _go.archmap[ansible_architecture] }}" - -- name: set go archive filename - ansible.builtin.set_fact: - go_archive: "go{{ _go.version }}.{{ ansible_system | lower }}-{{ arch }}.{{ _go.extmap[ansible_system] }}" - tags: - - dev - - go - - debug - -- name: create temp path - ansible.builtin.tempfile: - state: directory - prefix: go_dl. - register: d_go_dl_tmp - -- name: download go archive - become: true - ansible.builtin.get_url: - dest: "{{ d_go_dl_tmp.path }}/{{ go_archive }}" - url: "https://go.dev/dl/{{ go_archive }}" - checksum: "{{ _go[_go.version][ansible_system][arch] }}" - decompress: false - tags: - - dev - - go - -- name: ensure go install dir exists - become: true - ansible.builtin.file: - path: "{{ _go.install_path }}" - state: directory - -- name: extract go package - ansible.builtin.unarchive: - dest: "{{ _go.install_path }}" - src: "{{ d_go_dl_tmp.path }}/{{ go_archive }}" - remote_src: true - when: ansible_system == 'Linux' - become: true - -- name: install go macOS use pkg file +- name: check go version ansible.builtin.command: - cmd: "installer -pkg {{ d_go_dl_tmp.path }}/{{ go_archive }} -target /" - when: ansible_system == 'Darwin' - become: true - tags: - - dev - - go + cmd: "go version" + register: r_go_version + ignore_errors: true + +- name: install/update go + when: "'{{ _go.version }}' not in r_go_version.stdout" + block: + - name: set go arch + ansible.builtin.set_fact: + arch: "{{ _go.archmap[ansible_architecture] }}" + + - name: set go archive filename + ansible.builtin.set_fact: + go_archive: "go{{ _go.version }}.{{ ansible_system | lower }}-{{ arch }}.{{ _go.extmap[ansible_system] }}" + tags: + - dev + - go + - debug + + - name: create temp path + ansible.builtin.tempfile: + state: directory + prefix: go_dl. + register: d_go_dl_tmp + + - name: download go archive + become: true + ansible.builtin.get_url: + dest: "{{ d_go_dl_tmp.path }}/{{ go_archive }}" + url: "https://go.dev/dl/{{ go_archive }}" + checksum: "{{ _go[_go.version][ansible_system][arch] }}" + decompress: false + tags: + - dev + - go + + - name: ensure go install dir exists + become: true + ansible.builtin.file: + path: "{{ _go.install_path }}" + state: directory + + - name: extract go package + ansible.builtin.unarchive: + dest: "{{ _go.install_path }}" + src: "{{ d_go_dl_tmp.path }}/{{ go_archive }}" + remote_src: true + when: ansible_system == 'Linux' + become: true + + - name: install go macOS use pkg file + ansible.builtin.command: + cmd: "installer -pkg {{ d_go_dl_tmp.path }}/{{ go_archive }} -target /" + when: ansible_system == 'Darwin' + become: true + tags: + - dev + - go