- name: Get Go tar
  get_url: url=https://storage.googleapis.com/golang/go{{ go_version }}.linux-amd64.tar.gz dest=/tmp

- name: Install GO
  command: tar -C /usr/local -xzf /tmp/go{{ go_version }}.linux-amd64.tar.gz
  become: yes
  
- name: Add GOPATHS
  lineinfile:
    dest: "{{ item.file }}"
    insertafter: EOF
    line: "{{ item.line }}"
    follow: yes
  with_items:
    - { file: "/etc/profile", line: "export PATH=$PATH:/usr/local/go/bin" }
    - { file: "{{ansible_env.HOME}}/.profile", line: "export PATH=$PATH:{{go_path}}/bin" }
    - { file: "{{ansible_env.HOME}}/.profile", line: "export GOPATH={{go_path}}"}
  become: yes


- name: Create GOPATH
  file:
    path: "{{go_path}}"
    state: directory
    
- name: Install go packages
  command: /usr/local/go/bin/go get {{item}}
  environment:
    GOPATH: "{{go_path}}"
  with_items: go_packages

- name: Get Go tar
  get_url: url=https://storage.googleapis.com/golang/go{{ go_version }}.linux-amd64.tar.gz dest=/tmp

- name: Install GO
  unarchive:
    copy: no
    src: /tmp/go{{ go_version }}.linux-amd64.tar.gz
    dest: /usr/local
  become: yes
  
- name: Add GOPATHS
  lineinfile:
    dest: "{{ item.file }}"
    insertafter: EOF
    line: "{{ item.line }}"
    follow: yes
  with_items:
    - { file: "/etc/profile", line: "export PATH=$PATH:/usr/local/go/bin" }
    - { file: "{{ansible_env.HOME}}/.profile", line: "export PATH=$PATH:{{go_path}}/bin" }
    - { file: "{{ansible_env.HOME}}/.profile", line: "export GOPATH={{go_path}}"}
  become: yes


- name: Create GOPATH
  file:
    path: "{{go_path}}"
    state: directory
    
- name: Install go packages
  command: /usr/local/go/bin/go get {{item}}
  environment:
    GOPATH: "{{go_path}}"
  with_items: go_packages

Use unarchive instead of tar command
Use unarchive instead of tar command
