---
# Configuration for the nuancier webapp

- name: clean yum metadata
  command: yum clean all
  tags:
  - packages

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

- name: replace the fedora-elections configuration file by the one with the normal user
  template: src={{ item.file }}
            dest="{{ item.location }}/{{ item.file }}"
            owner=apache group=apache mode=0600
  with_items:
  - { file: fedora-elections.cfg, location: /etc/fedora-elections }
  - { file: fedora-elections.conf, location: /etc/httpd/conf.d }
  - { file: fedora-elections.wsgi, location: /var/www }
  - { file: alembic.ini, location: /etc/fedora-elections }
  tags:
  - config
  notify:
  - restart apache

- name: create the database scheme
  command: /usr/bin/python2 /usr/share/fedora-elections/fedora-elections_createdb.py
  environment:
      FEDORA_ELECTIONS_CONFIG: /etc/fedora-elections/fedora-elections.cfg
  tags:
  - config
  notify:
  - restart apache

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

- name: apply selinux type to static files
  file: >
    dest=/usr/lib/python2.6/site-packages/fedora_elections/static/
    setype=httpd_sys_content_t
    state=directory
    recurse=yes

- name: apply selinux type to the wsgi file
  file: >
    dest=/usr/share/fedora-elections/fedora-elections.wsgi
    setype=httpd_sys_content_t
