- 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

  roles:
  # The openshift/project role breaks if the project already exists:
  # https://pagure.io/fedora-infrastructure/issue/6404
  - role: openshift/project
    app: greenwave
    description: greenwave
    appowners:
    - dcallagh
    - gnaponie
    - lholecek
    - ralph
    - cverna
    tags:
      - apply-appowners
  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedmsg-key
    key: fedmsg-greenwave.key
    privatefile: fedmsg-certs/keys/greenwave-greenwave-web-greenwave.app.os.stg.fedoraproject.org.key
    when: env == "staging"
  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedmsg-crt
    key: fedmsg-greenwave.crt
    privatefile: fedmsg-certs/keys/greenwave-greenwave-web-greenwave.app.os.stg.fedoraproject.org.crt
    when: env == "staging"
  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedmsg-key
    key: fedmsg-greenwave.key
    privatefile: fedmsg-certs/keys/greenwave-greenwave-web-greenwave.app.os.fedoraproject.org.key
    when: env != "staging"
  - role: openshift/secret-file
    app: greenwave
    secret_name: greenwave-fedmsg-crt
    key: fedmsg-greenwave.crt
    privatefile: fedmsg-certs/keys/greenwave-greenwave-web-greenwave.app.os.fedoraproject.org.crt
    when: env != "staging"
  - role: openshift/object
    app: greenwave
    template: imagestream.yml
    objectname: imagestream.yml
  - role: openshift/object
    app: greenwave
    template: buildconfig.yml
    objectname: buildconfig.yml
    tags:
      - apply-buildconfig
  - role: openshift/object
    app: greenwave
    template: configmap.yml
    objectname: configmap.yml
  - role: openshift/object
    app: greenwave
    file: service.yml
    objectname: service.yml
  - role: openshift/route
    app: greenwave
    routename: web-pretty
    host: "greenwave{{ env_suffix }}.fedoraproject.org"
    serviceport: web
    servicename: greenwave-web
  # TODO -- someday retire this old route in favor of the pretty one above.
  - role: openshift/object
    app: greenwave
    file: route.yml
    objectname: route.yml
  - role: openshift/object
    app: greenwave
    template: deploymentconfig.yml
    objectname: deploymentconfig.yml
  - role: openshift/rollout
    app: greenwave
    dcname: greenwave-web

- name: Change the route haproxy default timeout
  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

  tasks:
    - name: Set the timeout to the openshift route
      command: "oc -n greenwave annotate route {{ item }} --overwrite haproxy.router.openshift.io/timeout=750s"
      with_items:
        - greenwave-web
        - web-pretty
  tags:
    - route-timeout
