From 9df5eac313e338d367d36b9df8a5c4dd7431de95 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 18 Apr 2016 13:38:51 -0400 Subject: [PATCH] golang: install whenever version does not match specified version --- roles/golang/tasks/main.yml | 48 +++++++++++++++++++++++++++++-------- roles/golang/vars/main.yml | 3 ++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/roles/golang/tasks/main.yml b/roles/golang/tasks/main.yml index 8869760..3275ad7 100644 --- a/roles/golang/tasks/main.yml +++ b/roles/golang/tasks/main.yml @@ -1,40 +1,68 @@ --- - name: check for existing go installation + tags: + - golang + stat: path="{{ golang_root }}/bin/go" + register: checked + +- name: determine version of existing go installation tags: - golang # Do not report changes from running shell command to check version changed_when: false + when: checked.stat.exists command: "{{ golang_root }}/bin/go version" - register: installed + register: version + +- name: check if go version matches {{ golang_version }} + tags: + - golang + when: checked.stat.exists and version|success + set_fact: + # Install when reported version does not match specified version + install: "{{ version.stdout.find(golang_version) == -1 }}" + +- name: cleanup existing go installation + tags: + - golang + when: checked.stat.exists and version|success and install + file: path={{ golang_root }} state=absent + +- name: install go because no installation present + tags: + - golang + when: checked.stat.exists == false + set_fact: + install: true - name: install git tags: - golang - when: installed|failed + when: install apt: pkg=git state=installed - name: install mercurial tags: - golang - when: installed|failed + when: install apt: pkg=mercurial state=installed -- name: download and checksum go tarball +- name: download and checksum {{ golang_version }} tarball tags: - golang - when: installed|failed + when: install get_url: url={{ golang_url }} dest={{ golang_tgz }} checksum=sha256:{{ golang_sha256 }} - name: unpack tarball tags: - golang - when: installed|failed + when: install unarchive: src={{ golang_tgz }} dest=/usr/local/ copy=no - name: insert go configuration into shell configuration tags: - golang - when: installed|failed + when: install blockinfile: dest: /{{ golang_user }}/.bashrc marker: "# {mark} ansible-managed Go configuration" @@ -47,17 +75,17 @@ - name: create personal GOPATH location tags: - golang - when: installed|failed + when: install file: path={{ golang_home_dir }}/src/{{ golang_personal_gopath }} state=directory - name: symlink personal GOPATH location to ~/go tags: - golang - when: installed|failed + when: install file: dest={{ golang_home_dir }}/go src={{ golang_home_dir }}/src/{{ golang_personal_gopath }} owner={{ golang_user }} group={{ golang_user }} state=link - name: remove temporary go tarball tags: - golang - when: installed|failed + when: install file: path={{ golang_tgz }} state=absent diff --git a/roles/golang/vars/main.yml b/roles/golang/vars/main.yml index 6eb46ed..7b8bdcc 100644 --- a/roles/golang/vars/main.yml +++ b/roles/golang/vars/main.yml @@ -4,7 +4,8 @@ golang_user: "root" golang_home_dir: "/root" golang_personal_gopath: "github.com/mdlayher" # Go installation configuration -golang_url: "https://storage.googleapis.com/golang/go1.6.1.linux-amd64.tar.gz" +golang_version: "go1.6.1" +golang_url: "https://storage.googleapis.com/golang/{{ golang_version }}.linux-amd64.tar.gz" golang_tgz: "/tmp/golang.tar.gz" golang_sha256: "6d894da8b4ad3f7f6c295db0d73ccc3646bce630e1c43e662a0120681d47e988" golang_root: "/usr/local/go"