Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ansible playbook to install latest Golang using godeb on Debian system
- # ansible-playbook latest-golang.yml -K
- ---
- - hosts: all
- vars:
- remote_user: alkemic
- user: "{{ remote_user }}"
- tasks:
- - name: Setup GOPATH in ~/.profile
- lineinfile: >
- dest=/home/{{ remote_user }}/.profile
- create=yes
- line="{{ item }}"
- with_items:
- - 'export GOPATH=/home/{{ remote_user }}/projects/go'
- - 'export PATH=$PATH:$GOPATH/bin'
- - name: Check if golang is installed
- command: which go
- register: go_check
- ignore_errors: True
- - name: Check if godeb is installed
- command: which godeb
- register: godeb_check
- ignore_errors: True
- - name: Install golang if missing
- become: yes
- apt:
- name: golang
- when: go_check.rc == 1
- - name: Install git
- become: yes
- apt:
- name: git
- - name: Install godeb if missing
- become: no
- shell: . /home/{{ remote_user }}/.profile && go get gopkg.in/niemeyer/godeb.v1/cmd/godeb
- when: godeb_check.rc == 1
- - shell: go version | sed -n -e 's/^go version go\\(.*\\) linux\\/.*$/\\1/p'
- register: go_version
- - shell: . /home/{{ remote_user }}/.profile && godeb list | head -1
- register: go_latest_version
- - debug: msg="{{ go_latest_version.stdout }} - {{ go_version.stdout}}"
- - name: Update Go
- become: no
- shell: . /home/{{ remote_user }}/.profile && godeb install
- when: go_latest_version.stdout != go_version.stdout
- - name: Install golang if missing
- become: yes
- apt:
- name: golang
- state: absent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement