- name: make the app be real
  hosts: os-masters[0]:os-masters-stg[0]
  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

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

  roles:
  - role: openshift/project
    app: bodhi
    description: bodhi
    appowners:
    - bowlofeggs
    - cverna
    tags:
      - apply-appowners
  - role: openshift/keytab
    app: bodhi
    key: koji-keytab
    secret_name: bodhi-keytab
    service: bodhi
    host: "bodhi{{ env_suffix }}.fedoraproject.org"
  - role: openshift/secret-file
    app: bodhi
    secret_name: bodhi-fedmsg-key
    key: fedmsg-bodhi.key
    privatefile: fedmsg-certs/keys/bodhi-bodhi01.stg.phx2.fedoraproject.org.key
    when: env == "staging"
  - role: openshift/secret-file
    app: bodhi
    secret_name: bodhi-fedmsg-key
    key: fedmsg-bodhi.key
    privatefile: fedmsg-certs/keys/bodhi-bodhi-web-temp-bodhi.app.os.fedoraproject.org.key
    when: env != "staging"
  - role: openshift/secret-file
    app: bodhi
    secret_name: bodhi-fedmsg-crt
    key: fedmsg-bodhi.crt
    privatefile: fedmsg-certs/keys/bodhi-bodhi01.stg.phx2.fedoraproject.org.crt
    when: env == "staging"
  - role: openshift/secret-file
    app: bodhi
    secret_name: bodhi-fedmsg-crt
    key: fedmsg-bodhi.crt
    privatefile: fedmsg-certs/keys/bodhi-bodhi-web-temp-bodhi.app.os.fedoraproject.org.crt
    when: env != "staging"
  - role: openshift/imagestream
    app: bodhi
    imagename: bodhi-web
  - role: openshift/object
    app: bodhi
    template: buildconfig.yml
    objectname: buildconfig.yml
    bodhi_version: 3.13.3-1.fc29.infra
    when: env == "staging"
  - role: openshift/object
    app: bodhi
    template: buildconfig.yml
    objectname: buildconfig.yml
    bodhi_version: 3.13.3-1.fc29.infra
    when: env != "staging"
  - role: openshift/start-build
    app: bodhi
    buildname: bodhi-web
  - role: openshift/object
    app: bodhi
    template_fullpath: "{{roles_path}}/bodhi2/base/templates/configmap.yml"
    objectname: configmap.yml
  - role: openshift/object
    app: bodhi
    file: service.yml
    objectname: service.yml
  - role: openshift/route
    app: bodhi
    routename: bodhi-web
    host: "bodhi{{ env_suffix }}.fedoraproject.org"
    serviceport: web
    servicename: bodhi-web
  - role: openshift/object
    app: bodhi
    template: deploymentconfig.yml
    objectname: deploymentconfig.yml
  - role: openshift/rollout
    app: bodhi
    dcname: bodhi-web

  post_tasks:
  - name: Scale up pods
    command: oc -n bodhi scale dc/bodhi-web --replicas={{ hostvars[groups['bodhi2'][0]]['openshift_pods'] }}
    when: env != "staging"
  - name: Scale up pods
    command: oc -n bodhi scale dc/bodhi-web --replicas={{ hostvars[groups['bodhi2-stg'][0]]['openshift_pods'] }}
    when: env == "staging"
