---
- name: Check if collect directory exists
  stat:
    path: "{{ artcl_collect_dir }}"
  register: collect_dir

- name: Create collect directory
  file:
    path: "{{ artcl_collect_dir }}"
    state: directory
  when: not collect_dir.stat.exists

- name: Create the reproducer-quickstart directory
  file:
    path: "{{ artcl_collect_dir }}/{{ old_reproducer_dir }}"
    state: directory

- name: Create the reproducer-quickstart/scripts directory
  file:
    path: "{{ artcl_collect_dir }}/{{ old_reproducer_dir }}/scripts"
    state: directory

- name: Copy the generate toci templates and files
  copy:
    src: "/home/{{ undercloud_user }}/src/git.openstack.org/openstack/tripleo-ci/{{ item }}"
    dest: "{{ artcl_collect_dir }}/{{ old_reproducer_dir }}/{{ item }}"
    mode: 0755
  with_items:
    - "toci_gate_test.sh"
    - "toci_quickstart.sh"
    - "scripts/common_vars.bash"
    - "scripts/oooq_common_functions.sh"

- name: Check if featureset-override exists
  stat:
    path: "/home/{{ undercloud_user }}/src/git.openstack.org/openstack/tripleo-ci/featureset-override.yaml"
  register: featureset_override_file

- name: Add the featureset-override if it exists
  copy:
    src: "/home/{{ undercloud_user }}/src/git.openstack.org/openstack/tripleo-ci/featureset-override.yaml"
    dest: "{{ artcl_collect_dir }}/{{ old_reproducer_dir }}/featureset-override.yaml"
    mode: 0755
  when: featureset_override_file.stat.exists

- name: Create the reproducer file from template
  template:
    src: "{{ reproducer_quickstart_script }}"
    dest: "{{ artcl_collect_dir }}/{{ old_reproducer_dir }}/reproducer-quickstart.sh"
    mode: 0755

- name: Create reproducer script documentation from template
  template:
    src: README-reproducer-quickstart.html.j2
    dest: "{{ reproducer_quickstart_readme_file }}"
