- name: Create directories
  file:
    path:
      - "{{ bamboo_root }}"
      - "/home/zoox/bamboo-agent-home/"
    state: directory

- name: Add openjdk-8 PPA
  apt_repository:
    repo: ppa:openjdk-r/ppa
  become: yes

- name: Install java 8
  apt:
    update_cache: yes
    cache_valid_time: 3600
    force_apt_get: yes
    name: openjdk-8-jdk
  become: yes

- name: set java 8 to default
  alternatives:
    name: java
    path: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

- name: Download bamboo remote agent jar file
  get_url:
    url: https://bamboo.zooxlabs.com/agentServer/agentInstaller/atlassian-bamboo-agent-installer-6.10.2.jar
    dest: "{{ bamboo_root }}atlassian-bamboo-agent-installer.jar"
    mode: '0644'
    checksum: sha512:6b7db1219a44a334127a1c4774133e888f4acfa3852b4a2e37b272067252879ca9067e16add2eb8317eda2703c12ed17318b078d065011a5141be4bf21f8ac5c

- name: Enable git auto prune to clean dead branches
  git_config:
    name: fetch.prune
    scope: global
    value: 'true'

- name: Clone driving for CI
  git:
    repo: git@git.zooxlabs.com:zooxco/driving.git
    dest: "{{ bamboo_root }}/driving"
    version: "{{ imaging_ci_git_hash | default('HEAD') }}"

- name: Install upstart service for remote agent
  copy:
    src: "bamboo-agent-imaging-ci.conf"
    dest: "/etc/init/bamboo-agent-imaging-ci.conf"
    owner: root
    group: root
    mode: '644'
  notify:
    - reload upstart configuration
    - restart remote agent service
  become: yes
