---
# tasklist for setting up upstreamfirst-monitor (uf-monitor) on an el7 host


- name: Install docker
  package: name={{item}} state=present
  with_items:
  - docker
  - python-docker-py

- name: Run docker
  service: name=docker state=started enabled=yes

- name: Pull apiserver image
  docker_image:
    name: "{{ apiserver_container_image }}"
    tls_verify: true

- name: Pull updater image
  docker_image:
    name: "{{ apiserver_container_image }}"
    tls_verify: true

- name: ensure ufmonitor database is created
  become: true
  become_user: postgres
  postgresql_db: db={{ ufmonitor_db_name }}

- name: ensure ufmonitor db user has access to dev database
  become: true
  become_user: postgres
  postgresql_user: db={{ ufmonitor_db_name }} user={{ ufmonitor_db_user }} password={{ ufmonitor_db_password }} role_attr_flags=NOSUPERUSER

- name: Deploy service file for apiserver
  template: src=ufmonitor-apiserver.service.j2 dest=/etc/systemd/system/ufmonitor-apiserver.service
  notify:
  - reload systemd

- name: Enable apiserver
  service: name=ufmonitor-apiserver enabled=yes

- name: install script to update ufmonitor database
  template: src=update-ufmonitor.j2 dest=/usr/local/bin/update-ufmonitor mode=0755

- name: Setup cron to update ufmonitor database
  cron: name="update-ufmonitor-database" minute="15" user="root"
        job="/usr/local/bin/update-ufmonitor > /dev/null"
        cron_file=update-ufmonitor-database

- name: ensure ufmonitor document root exists
  file: path="{{ ufmonitor_home }}" state=directory owner=apache group=apache mode=0775

- name: copy over index.html
  template: src=index.html.j2 dest="{{ ufmonitor_home }}/index.html" owner=apache group=apache mode=0775

- name: copy over static support files
  copy: src=media dest="{{ ufmonitor_home }}" owner=apache group=apache mode=0775

- name: generate httpd config
  template: src=ufmonitor.conf.j2 dest=/etc/httpd/conf.d/ufmonitor.conf mode=0755

