---
- name: default copr_builder_fedora_version
  set_fact:
    copr_builder_fedora_version: 0
  when:
    - copr_builder_fedora_version is not defined
  tags:
    - always

# Warning: this file is included also from copr-hv playbook(s), so keep the
# source file arguments absolute (not relative to this role)
- name: sync copr provisioning files
  synchronize: src="{{ roles_path }}/copr/backend/files/provision/"
               dest="{{ provision_directory }}/"
  tags:
  - provision_config

- name: "sync copr provisioning files [remove mock config leftovers]"
  synchronize: src="{{ roles_path }}/copr/backend/files/provision/files/mock/"
               dest="{{ provision_directory }}/files/mock/"
               delete=yes
  tags:
  - provision_config

- name: resalloc, generate vars.yml file
  template:
    src: "{{ roles_path }}/copr/backend/templates/provision/{{ item }}"
    dest: "{{ provision_directory }}/{{ item }}"
  with_items:
  - vars.yml
  tags:
  - provision_config

- name: templated provision scripts
  template:
    src: "{{ roles_path }}/copr/backend/templates/provision/{{ item }}"
    dest: "{{ provision_directory }}/{{ item }}"
    mode: 0755
  with_items:
  - upload-qcow2-images
  tags:
  - provision_config
  when:
  # for the hypervisor use-case
  - cloud_vars is not defined

- name: templated provision scripts
  template:
    src: "{{ roles_path }}/copr/backend/templates/provision/{{ item }}"
    dest: "{{ provision_directory }}/{{ item }}"
    mode: 0755
  with_items:
  - libvirt-new
  tags:
  - provision_config
  when:
  - cloud_vars is defined and cloud_vars

- name: generate cloud-oriented vars files
  template:
    src: "{{ roles_path }}/copr/backend/templates/provision/{{ item }}"
    dest: "{{ provision_directory }}/{{ item }}"
  with_items:
  - nova_cloud_vars.yml
  - aws_cloud_vars.yml
  tags:
  - provision_config
  when:
  - cloud_vars is defined and cloud_vars

- name: put copr-rpmbuild configuration file into the provision subdir
  template: src="{{ roles_path }}/copr/backend/templates/provision/copr-rpmbuild/main.ini.j2"
            dest="{{ provision_directory }}/files/main.ini"
  tags:
  - provision_config
  - copr_rpmbuild_main_ini

- name: put rpkg configuration file into the provision subdir
  template: src="{{ roles_path }}/copr/backend/templates/provision/rpkg.conf.j2"
            dest="{{ provision_directory }}/files/rpkg.conf"
  tags:
  - provision_config

- name: remove currently unused and broken os_nova filter
  file: state=absent
        path="{{ provision_directory }}/filter_plugins/os_nova.py"
  tags:
  - provision_config

- name: install the Oregon State University OpenStack token file on BE/HV
  template:
    src: "{{ roles_path }}/copr/backend/templates/provision/rc-osuosl.sh.j2"
    dest: "{{ provision_directory }}/.rc-osuosl.sh"
    owner: "{{ provision_user }}"
    group: "{{ provision_user }}"
    mode: 0600
  tags:
  - provision_config
