- name: prepare setting up the database
  hosts: db01.stg.iad2.fedoraproject.org:db01.iad2.fedoraproject.org
  gather_facts: no
  user: root

  tasks:
  - name: install psycopg2 for the postgresql ansible modules
    package: name=python3-psycopg2 state=present
    tags:
    - packages

- name: setup the database
  hosts: db01.stg.iad2.fedoraproject.org
  gather_facts: no
  become: yes
  become_user: postgres
  vars_files:
  - /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - "/srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml"

  tasks:
  - name: Create the database user
    postgresql_user:
      name: "{{ stg_blockerbugs_db_user }}"
      password: "{{ stg_blockerbugs_db_password }}"
  - name: Create the database itself
    postgresql_db:
      name: "blockerbugs"
      owner: "{{ stg_blockerbugs_db_user }}"
      encoding: UTF-8
  - name: Test the database creation
    postgresql_db:
      name: "blockerbugs"
      owner: "{{ stg_blockerbugs_db_user }}"
      encoding: UTF-8

- name: setup the database
  hosts: db01.iad2.fedoraproject.org
  gather_facts: no
  become: yes
  become_user: postgres
  vars_files:
  - /srv/web/infra/ansible/vars/global.yml
  - "/srv/private/ansible/vars.yml"
  - "/srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml"

  tasks:
  - name: Create the database user
    postgresql_user:
      name: "{{ prod_blockerbugs_db_user }}"
      password: "{{ prod_blockerbugs_db_password }}"
  - name: Create the database itself
    postgresql_db:
      name: "blockerbugs"
      owner: "{{ prod_blockerbugs_db_user }}"
      encoding: UTF-8
  - name: Test the database creation
    postgresql_db:
      name: "blockerbugs"
      owner: "{{ prod_blockerbugs_db_user }}"
      encoding: UTF-8

- name: make the app be real
  hosts: os_control_stg[0]:os_control[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:
  - role: openshift/project
    app: blockerbugs
    description: Blockerbugs
    appowners:
    - frantisekz
    - adamwill
    alert_users:
    - frantisekz
    tags:
      - appowners

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

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

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

  - role: openshift/object
    app: blockerbugs
    file: service.yml
    objectname: service.yml

  - role: openshift/object
    app: blockerbugs
    template: secret.yml
    objectname: secret.yml

  - role: openshift/object
    app: blockerbugs
    template: cron.yml
    objectname: cron.yml

  - role: openshift/route
    app: blockerbugs
    routename: blockerbugs
    host: "qa{{ env_suffix }}.fedoraproject.org"
    path: "/blockerbugs"
    serviceport: 8080-tcp
    servicename: blockerbugs

  - role: openshift/route
    app: blockerbugs
    routename: qa-landing
    host: "qa{{ env_suffix }}.fedoraproject.org"
    serviceport: 8080-tcp
    servicename: qa-landing
    annotations:
         haproxy.router.openshift.io/set-forwarded-headers: append

  - role: openshift/start-build
    app: blockerbugs
    buildname: blockerbugs-build
    objectname: blockerbugs-build
