---
- hosts: all
  become: yes
  become_user: root
  tasks:
  - name: Install Packages Needed To Compile git
    apt: pkg={{ item }} state=latest
    with_items:
      - libcurl4-openssl-dev
      - libexpat1-dev
      - gettext
      - zlib1g-dev
      - libssl-dev
      - build-essential
      - autoconf

  - name: Extract release
    become: no
    shell: curl -L --progress https://github.com/git/git/archive/v2.8.3.tar.gz | tar xz
    args:
      chdir: /usr/local/src/
      
  - name: Move source to canonical directory
    become: yes
    shell: rm -rf /usr/local/src/git/ && mv /usr/local/src/git-2.8.3/ /usr/local/src/git/

  - name: Make the buildconf
    become: no
    shell: make configure
    args:
      chdir: /usr/local/src/git

  - name: Configure the build
    become: no
    shell: ./configure
    args:
      chdir: /usr/local/src/git

  - name: Build git
    become: no
    shell: make prefix=/usr/local all
    args:
      chdir: /usr/local/src/git

  - name: Remove existing git
    apt: pkg=git state=absent purge=no

  - name: Install git
    shell: make prefix=/usr/local install
    args:
      chdir: /usr/local/src/git