---
- name: install ci_resultsdb's
  package: name={{ item }} state=present
  with_items:
    - python-ci-resultsdb-listener
    - libsemanage-python
    - rdbsync

- name: Create /etc/pki/fedmsg/
  file: name=/etc/pki/fedmsg
        state=directory
        recurse=yes
        owner=root group=root
  tags:
  - config

- name: install fedmsg ca.cert
  copy: >
    src="{{ private }}/files/fedmsg-certs/keys/ca.crt"
    dest=/etc/pki/fedmsg/ca.crt
    owner=root
    group=root
    mode=0644
  tags:
  - config

- name: Create /etc/ci-resultsdb-listener/
  file: name=/etc/ci-resultsdb-listener/
        state=directory
        recurse=yes
        owner=root group=root
  tags:
  - config

- name: generate ci-resultsdb config files and override default resultsdb settings
  template: src={{ item.file }}
            dest={{ item.location }}/{{ item.file }}
            owner=root group=root mode=0644
  with_items:
  - { file: listener.cfg, location: /etc/ci-resultsdb-listener/ }
  - { file: endpoints.py, location: /etc/fedmsg.d/ }
  - { file: ci-resultsdb-listener.py, location: /etc/fedmsg.d/ }
  - { file: settings.py, location: /etc/resultsdb/ }
  - { file: cert.conf, location: /etc/httpd/conf.d/ }
  notify:
    - reload httpd

- name: Start and enable the fedmsg-hub service
  service: name={{ item }} enabled=yes state=started
  with_items:
  - fedmsg-hub

- name: letsencrypt cert
  include_role: name=certbot
  tags:
  - config
  - certbot

- name: Check that cert file exists
  stat:
    path: "/etc/letsencrypt/live/resultsdb.ci.centos.org/cert.pem"
  register: stat_cert
  tags:
  - config
  - certbot

- name: Should admin run certbot?
  fail:
    msg: Please see roles/certbot/README step (3) and manually run certbot
  when:
    - stat_cert.stat.exists == False
  tags:
  - config
  - certbot

