- hosts: all
  tasks:
    # Copy openstack logs once tempest run finishes
    - name: Copy openstack services logs once tempest run finish
      shell:
         cmd: |
           set -e
           set -x
           source ./tools/copy-logs.sh
           recover_default_logs
         executable: /bin/bash
         chdir: '{{ ansible_user_dir }}/workspace/packstack'
      environment: '{{ zuul }}'

    - name: Create tempest directory in /tmp/logs
      file:
        path: /tmp/logs/tempest
        state: directory
      become: true

    - name: Copying tempest logs and config to /tmp/logs/tempest
      copy:
        src: "{{ item }}"
        dest: /tmp/logs/tempest
        remote_src: true
      with_items:
        - /opt/stack/tempest/etc/tempest.conf
        - /opt/stack/tempest/tempest.log
        - /etc/openstack/accounts.yaml
      ignore_errors: true
      become: true

    - name: Upload logs
      synchronize:
        src: '/tmp/logs'
        dest: '{{ zuul.executor.log_root }}'
        mode: pull
        copy_links: true
        verify_host: true
        rsync_opts:
          - --include=/logs/**
          - --include=*/
          - --exclude=*
          - --prune-empty-dirs
