---
- name: provision CoreOS Cincinnati backend
  hosts: os_control:os_control_stg
  user: root
  gather_facts: false

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - "/srv/private/ansible/vars.yml"
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
    - /srv/web/infra/ansible/roles/openshift-apps/coreos-cincinnati/vars/{{ env }}.yml

  pre_tasks:
  - include_vars: dir=/srv/web/infra/ansible/vars/all/ ignore_files=README

  ############################################
  # actions to create the project in OpenShift
  ############################################
  # to run: sudo rbac-playbook -l os_control_stg openshift-apps/coreos-cincinnati.yml
  roles:
  - role: openshift/project
    app: coreos-cincinnati
    description: Fedora CoreOS Cincinnati backend
    appowners:
    - jlebon
    - dustymabe
    - siosm

  - role: openshift/object
    app: coreos-cincinnati
    template: imagestream.yml
    objectname: imagestream.yml

  - role: openshift/object
    app: coreos-cincinnati
    template: buildconfig.yml
    objectname: buildconfig.yml

  - role: openshift/start-build
    app: coreos-cincinnati
    buildname: coreos-cincinnati-build
    objectname: coreos-cincinnati-build

  - role: openshift/object
    app: coreos-cincinnati
    template: config-stub.yml
    objectname: config-stub.yml

  - role: openshift/object
    app: coreos-cincinnati
    template: deploymentconfig.yml
    objectname: deploymentconfig.yml

  - role: openshift/rollout
    app: coreos-cincinnati
    dcname: coreos-cincinnati
    tags: [never, rollout]

  - role: openshift/object
    app: coreos-cincinnati
    template: service.yml
    objectname: service.yml

  - role: openshift/object
    app: coreos-cincinnati
    template: servicemonitor.yml
    objectname: servicemonitor.yml

  - role: openshift/route
    app: coreos-cincinnati
    routename: coreos-updates
    host: "updates.coreos{{ env_suffix }}.fedoraproject.org"
    serviceport: coreos-cincinnati-updates
    servicename: coreos-cincinnati

  - role: openshift/route
    app: coreos-cincinnati
    routename: coreos-updates-status
    host: "status.updates.coreos{{ env_suffix }}.fedoraproject.org"
    serviceport: coreos-cincinnati-updates-status
    servicename: coreos-cincinnati

  - role: openshift/route
    app: coreos-cincinnati
    routename: coreos-updates-raw
    host: "raw-updates.coreos{{ env_suffix }}.fedoraproject.org"
    serviceport: coreos-cincinnati-raw-updates
    servicename: coreos-cincinnati

  - role: openshift/route
    app: coreos-cincinnati
    routename: coreos-updates-raw-status
    host: "status.raw-updates.coreos{{ env_suffix }}.fedoraproject.org"
    serviceport: coreos-cincinnati-raw-updates-status
    servicename: coreos-cincinnati

  ###############################################
  # actions to delete the project from OpenShift
  ###############################################
  # to run: sudo rbac-playbook -l os_control_stg -t delete openshift-apps/coreos-cincinnati.yml
  - role: openshift/object-delete
    app: coreos-cincinnati
    objecttype: project
    objectname: coreos-cincinnati
    tags: [never, delete]
