---

- include: ebs_volume.yml
  vars:
    ebs_volume_fs_type: "{{volume_fs_type}}"
    ebs_volume_dev: "{{volume_dev}}"
    ebs_volume_mount_point: "{{volume_mount_point}}"
  when: do_mount_format|bool

- block:
  - name: create project directory
    file:
      path: /etc/docker-compose/bamboo-server/
      mode: 0755
      state: directory
    notify: bounce bamboo-server

  - name: Download bamboo SSH patch jar
    get_url:
      url: https://artifactory.zooxlabs.com/artifactory/pipedream-generic/atlassian-bamboo-plugin-ssh-6.10.2-BSP-44126.jar
      dest: /etc/docker-compose/bamboo-server/atlassian-bamboo-plugin-ssh-6.10.2.jar
      mode: 0644
    notify: bounce bamboo-server

  - name: copy docker-compose.yml
    template:
      src: docker-compose.yml
      dest: /etc/docker-compose/bamboo-server/docker-compose.yml
    notify: bounce bamboo-server

  - name: copy Dockerfile
    copy:
      src: Dockerfile
      dest: /etc/docker-compose/bamboo-server/Dockerfile
    notify: bounce bamboo-server

  - name: copy ehcache
    copy:
      src: ehcache.xml
      dest: /etc/docker-compose/bamboo-server/ehcache.xml
    notify: bounce bamboo-server

  - name: copy properties file
    copy:
      src: bamboo-init.properties
      dest: /etc/docker-compose/bamboo-server/bamboo-init.properties
    notify: bounce bamboo-server

  - name: copy AD configuration file
    template:
      src: atlassian-user-custom.xml
      dest: "{{volume_mount_point}}/xml-data/configuration/atlassian-user-custom.xml"
    notify: bounce bamboo-server

  - name: start bamboo-server
    docker_compose:
      project_src: /etc/docker-compose/bamboo-server
      state: present

  - name: install psql client
    become: yes
    apt:
      name: "postgresql-client"
      state: present
      update_cache: yes
      cache_valid_time: 3600

  become: yes
