---
- include: script-log-deploy.yml
- hosts: enterpriselbservers
  vars_files:
    - vars.yml
    - host_vars/{{ env }}

  tasks:
    - name: Download enterprise portal artifact
      get_url: url=https://artifacts.hourlynerd.com/artifacts/{{ artifact_name }}/{{ artifact_version }} dest=/tmp/{{ artifact_name }}.tgz force=yes url_username={{ ci_artifact_username }} url_password={{ ci_artifact_password }}

    - name: Clean up enterprise app directory
      file: name={{ artifact_install_location }} state=absent force=yes
      sudo: true

    - name: Setup enterprise directory
      file: name={{ artifact_install_location }} state=directory owner={{ user }} group={{ user }} mode=0755
      sudo: true

    - name: Install enterprise portal artifact
      unarchive: src=/tmp/{{ artifact_name }}.tgz dest={{ artifact_install_location }} copy=no

    - name: Drop in the robots.txt file
      copy: src=files/robots.txt dest={{ artifact_install_location }}/dist/robots.txt mode=0644

    - name: HipChat notify that portal is deployed
      hipchat: token={{ hipchat_token }} validate_certs=no room=Deployments msg="[Enterprise Portal:{{ env }}] {{ inventory_hostname }} updated to revision {{ artifact_version }}"
      ignore_errors: true
      when: env != 'local'
