---
- name: Create /opt/stack directory
  file:
    path: /opt/stack
    owner: "{{ ansible_user }}"
    group: "{{ ansible_user }}"
    state: directory
  become: true

- name: Link /opt/stack/new to /opt/stack for backwards compat
  file:
    src: /opt/stack
    dest: /opt/stack/new
    owner: "{{ ansible_user }}"
    group: "{{ ansible_user }}"
    state: link
  become: true

- name: Set up git credentials
  shell: >
    git config --global user.email "user@example.com";
    git config --global user.name "CI user"

- include_tasks: patch_repos.yml
  with_items: "{{ repos }}"
  loop_control:
    loop_var: repo_item

- name: Set oooq extras to install from local copy
  copy:
    dest: /opt/stack/tripleo-quickstart/quickstart-extras-requirements.txt
    content: "git+file:///opt/stack/tripleo-quickstart-extras/#egg=tripleo-quickstart-extras\n"

- name: Add additional repos to quickstart-extras-requirements.txt
  lineinfile:
    dest: /opt/stack/tripleo-quickstart/quickstart-extras-requirements.txt
    line: "git+file:///opt/stack/{{ item }}/#egg={{ item }}"
  with_items:
    - "browbeat"
    - "tripleo-ha-utils"

- name: Create /opt/cache/files directory
  file:
    path: /opt/cache/files
    owner: "{{ ansible_user }}"
    group: "{{ ansible_user }}"
    state: directory
  become: true

- name: Download Cirros image
  get_url:
    url: "{{ nodepool_cirros_url }}"
    dest: "{{ nodepool_cirros_dest }}"
    checksum: "{{ nodepool_cirros_checksum }}"
