- name: Package all JARs
  local_action: shell cd ../java/ && gradle build
  become: false

- name: Deploy the executable uber JAR
  copy:
    src: "../java/{{ application }}/build/libs/{{ application }}-1.0.jar"
    dest: "/opt/{{ application }}.jar"
    owner: ubuntu
    group: ubuntu
    mode: 0500

- name: Make sure that the logging directory exists
  file:
    path: /var/log/apps/
    state: directory
    owner: ubuntu
    group: ubuntu
    mode: 0755

- name: Provide a conf file to run it as a service
  copy:
    src: templates/app.conf
    dest: "/opt/{{ application }}.conf"
    owner: root
    group: root
    mode: 0400

- name: Link the JAR so it can be managed as a service through init.d
  file:
    src: "/opt/{{ application }}.jar"
    dest: "/etc/init.d/{{ application }}"
    state: link
    owner: ubuntu
    group: ubuntu

- name: Restart the JAR and make sure it autostarts
  service: name="{{ application }}" state=restarted enabled=yes

- name: Store the deployment event in Elasticsearch so it can be used as an annotation
  command: >
    curl -XPOST "{{ elasticsearch_host }}/events/deployment"
         -u "{{ elasticsearch_user }}:{{ elasticsearch_password }}"
         -H "Content-Type: application/json"
         -d '{"@timestamp": "{{ ansible_date_time.iso8601 }}", "application": "{{ application }}", "host": "{{ inventory_hostname }}"}'

- name: Package all JARs
  local_action: shell cd ../java/ && gradle build
  become: false

- name: Deploy the executable uber JAR
  copy:
    src: "../java/{{ application }}/build/libs/{{ application }}-1.0.jar"
    dest: "/opt/{{ application }}.jar"
    owner: ubuntu
    group: ubuntu
    mode: 0500

- name: Make sure that the logging directory exists
  file:
    path: /var/log/apps/
    state: directory
    owner: ubuntu
    group: ubuntu
    mode: 0755

- name: Provide a conf file to run it as a service
  copy:
    src: templates/app.conf
    dest: "/opt/{{ application }}.conf"
    owner: root
    group: root
    mode: 0400

- name: Link the JAR so it can be managed as a service through init.d
  file:
    src: "/opt/{{ application }}.jar"
    dest: "/etc/init.d/{{ application }}"
    state: link
    owner: ubuntu
    group: ubuntu

- name: Restart the JAR, make sure it autostarts, and reload the configuration
  systemd: name="{{ application }}" state=restarted enabled=yes daemon_reload=yes

- name: Store the deployment event in Elasticsearch so it can be used as an annotation
  command: >
    curl -XPOST "{{ elasticsearch_host }}/events/deployment"
         -u "{{ elasticsearch_user }}:{{ elasticsearch_password }}"
         -H "Content-Type: application/json"
         -d '{"@timestamp": "{{ ansible_date_time.iso8601 }}", "application": "{{ application }}", "host": "{{ inventory_hostname }}"}'

ADD daemon reloading for Systemd
ADD daemon reloading for Systemd
