# This playbook will clone repos and set up a directory
# structure for running the launcher-playbook to start
# the Zuul-based reproducer and run a job.

{% raw %}
- name: setup
  hosts: localhost
  tasks:
    - name: Create directory structure
      file:
        path: "{{ item }}"
        state: directory
      with_items:
        - git
        - roles
        - library
        - playbooks/tripleo-ci-reproducer

    - name: Clone repos needed for reproducer
      git:
        repo: https://git.openstack.org/openstack/tripleo-quickstart.git
        dest: "git/tripleo-quickstart"
        version: 'FETCH_HEAD'
        accept_hostkey: true
        update: no
        refspec: "{{ ooo_quickstart_refspec | default('HEAD') }}"

    - name: Clone ansible role for reproducer
      git:
        repo: https://github.com/rdo-infra/ansible-role-tripleo-ci-reproducer.git
        dest: "git/ansible-role-tripleo-ci-reproducer"
        version: 'FETCH_HEAD'
        accept_hostkey: true
        update: no
        refspec: "{{ reproducer_role_refspec | default('HEAD') }}"

    - name: Copy roles and libraries for tripleo-quickstart
      synchronize:
        src: 'git/tripleo-quickstart/{{ item }}/'
        dest: '{{ item }}/'
      with_items:
        - roles
        - library

    - name: Copy setup files from tripleo-quickstart
      synchronize:
        src: 'git/tripleo-quickstart/{{ item }}'
        dest: "./{{ item }}"
      with_items:
        - install-deps.sh

    - name: requirements from ansible-role-tripleo-ci-reproducer
      synchronize:
        src: 'git/ansible-role-tripleo-ci-reproducer/{{ item }}'
        dest: './{{ item }}'
      with_items:
        - bindep.txt
        - requirements.txt

    - name: Copy ansible-role-tripleo-ci-reproducer roles and playbooks
      synchronize:
        src: 'git/ansible-role-tripleo-ci-reproducer{{ item.src_dir }}'
        dest: '{{ item.dest_dir }}/'
      with_items:
        - { src_dir: '', dest_dir: 'roles' }
        - { src_dir: '/playbooks/tripleo-ci-reproducer/', dest_dir: 'playbooks/tripleo-ci-reproducer' }
{% endraw %}
