- name: ensure packages required for buildmaster are installed
  action: yum name={{ item }} state=latest
  with_items:
    - buildbot
    - buildbot-master
    - libsemanage-python
    - python-psycopg2

- name: ensure packages required for buildmaster are installed
  action: yum name={{ item }} state=latest
  when: deployment_type == 'qadevel-prod' or deployment_type == 'qadevel-stg'
  with_items:
    - python-novaclient

- name: add the buildmaster user
  user: name={{ master_user }}

- name: allow httpd tcp connections with selinux
  seboolean: name=httpd_can_network_connect state=true persistent=yes

- name: copy httpd config
  template: src=buildmaster.conf.j2 dest=/etc/httpd/conf.d/buildmaster.conf owner=root group=root
  notify:
    - restart httpd

- name: ensure buildmaster database is created
  when: buildmaster_db_host != 'localhost'
  delegate_to: "{{ buildmaster_db_host }}"
  sudo: true
  sudo_user: postgres
  action: postgresql_db db={{ buildmaster_db_name }}

- name: ensure dev db user has access to dev database
  when: deployment_type == 'dev'
  delegate_to: "{{ buildmaster_db_host }}"
  sudo: true
  sudo_user: postgres
  action: postgresql_user db={{ buildmaster_db_name }} user={{ dev_buildmaster_db_user }} password={{ dev_buildmaster_db_password }} role_attr_flags=NOSUPERUSER

- name: ensure stg db user has access to stg database
  when: deployment_type == 'stg'
  delegate_to: "{{ buildmaster_db_host }}"
  sudo: true
  sudo_user: postgres
  action: postgresql_user db={{ buildmaster_db_name }} user={{ stg_buildmaster_db_user }} password={{ stg_buildmaster_db_password }} role_attr_flags=NOSUPERUSER

- name: ensure prod db user has access to prod database
  when: deployment_type == 'prod'
  delegate_to: "{{ buildmaster_db_host }}"
  sudo: true
  sudo_user: postgres
  action: postgresql_user db={{ buildmaster_db_name }} user={{ prod_buildmaster_db_user }} password={{ prod_buildmaster_db_password }} role_attr_flags=NOSUPERUSER
