---
# Set up Go.

- name: install go
  unarchive:
    src: 'https://storage.googleapis.com/golang/go{{ go_version }}.linux-{{ {"x86_64": "amd64", "i386": "386"}[ansible_architecture] }}.tar.gz'
    remote_src: yes
    dest: /usr/local
    mode: 0777
    creates: /usr/local/go/bin/go

- name: set go env. vars. and add go to path
  blockinfile:
    dest: '$HOME/.bashrc'
    block: |
      export PATH=$PATH:/usr/local/go/bin
      export GOPATH=$HOME
    state: present
    create: yes
    mode: 0644
  become: '{{ item }}'
  with_items:
    - true  # Run as root
    - false # Run as SSH user

- name: source ~/.bashrc from ~/.bash_profile
  lineinfile:
    dest: '$HOME/.bash_profile'
    line: '[ -r $HOME/.bashrc ] && source $HOME/.bashrc'
    state: present
    create: yes
    mode: 0644
  become: '{{ item }}'
  with_items:
    - true  # Run as root
    - false # Run as SSH user
