---
# Configuration for the fedocal webapp

- name: install needed packages
  yum: pkg={{ item }} state=present
  with_items:
  - fedocal
  - python-psycopg2
  - python-openid-cla
  - python-openid-teams
  - python-memcached
  - libsemanage-python
  tags:
  - packages

- name: copy sundry fedocal configuration
  template: src={{ item.file }}
            dest={{ item.location }}/{{ item.dest }}
            owner=apache group=apache mode=0600
  with_items:
  - { file: fedocal.cfg, location: /etc/fedocal, dest: fedocal.cfg }
  - { file: alembic.ini, location: /etc/fedocal, dest: alembic.ini }
  changed_when: "1 != 1"
  tags:
  - config
  notify:
  - restart apache

#- name: create the database scheme
#  command: /usr/bin/python2 /usr/share/fedocal/fedocal_createdb.py
#  environment:
#      FEDOCAL_CONFIG: /etc/fedocal/fedocal.cfg

- name: Install all the configuration file of fedocal
  template: src={{ item.file }}
            dest={{ item.location }}/{{ item.file }}
            owner=apache group=apache mode=0600
  with_items:
  - { file: fedocal.cfg, location: /etc/fedocal }
  - { file: alembic.ini, location: /etc/fedocal }
  - { file: fedocal.conf, location: /etc/httpd/conf.d }
  - { file: fedocal.wsgi, location: /var/www/ }
  tags:
  - config
  notify:
  - restart apache

- name: Install the reminder cron job
  when: inventory_hostname.startswith(('fedocal01.stg', 'fedocal02'))
  template: src={{ item.file }}
            dest={{ item.location }}/{{ item.file }}
  with_items:
  - { file: 'fedocal-reminder.cron', location: /etc/cron.d }
  tags:
  - config

- name: set sebooleans so fedocal can talk to the db
  action: seboolean name=httpd_can_network_connect_db
                    state=true
                    persistent=true

