---
- hosts: webservers
  vars_files:
    - vars.yml
    - host_vars/{{ env }}

  tasks:
    - name: Download 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: Setup tmp directory
      file: name={{ tmp_artifact_install_location }} state=directory owner={{ user }} group={{ user }} mode=0755
      sudo: true

    - name: Setup sourcemaps directory
      file: name=/var/hourlynerd/sourcemaps state=directory owner={{ user }} group={{ user }} mode=0755
      sudo: true

    - name: Unarchive artifact
      unarchive: src=/tmp/{{ artifact_name }}.tgz dest={{ tmp_artifact_install_location }} copy=no

    - name: Copy map and javascript files
      shell: cp -r {{ tmp_artifact_install_location }}/dist/scripts/* /var/hourlynerd/sourcemaps