---
- hosts: "{{ server }}"
  become: true

  tasks:
  
    - name: Create {{ branch }} dir
      file:
        path: /var/www/ui-components/test-results/{{ branch }}
        state: directory
        owner: nginx
        group: nginx
     
    - name: Clean {{ branch }} dir
      shell: rm -rf /var/www/ui-components/test-results/{{ branch }}/*

    - name: Sync bundle
      synchronize:
        src: ../coverage
        dest: /tmp
        recursive: yes

    - name: Copy release to folders
      shell: cp -r /tmp/coverage/* /var/www/ui-components/test-results/{{ branch }}/

    - name: Chown
      shell: chown -R nginx:nginx /var/www/ui-components/test-results/{{ branch }}

    - name: Delete temp dir
      file: 
        path: /tmp/coverage
        state: absent
