---
# Configuration for the nuancier webapp

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

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

- name: create pictures folder where we upload the pictures
  action: file state=directory
               path=/var/cache/nuancier/pictures
               owner=apache group=apache mode=0700
  tags:
  - setup
  - nuancier

- name: create the cache folder where nuancier creates the thumbnails
  action: file state=directory
               path=/var/cache/nuancier/cache
               owner=apache group=apache mode=0700
  tags:
  - setup
  - nuancier

- name: create the database scheme
  command: /usr/bin/python2 /usr/share/nuancier/nuancier_createdb.py
  environment:
      NUANCIER_CONFIG: /etc/nuancier/nuancier.cfg
  changed_when: "1 != 1"
  tags:
  - nuancier

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

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

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

- name: set sebooleans so apache can use glusterfs
  action: seboolean name=httpd_use_fusefs
                    state=true
                    persistent=true
  tags:
  - nuancier
  - selinux

- name: set sebooleans so apache can send emails
  action: seboolean name=httpd_can_sendmail
                    state=true
                    persistent=true
  tags:
  - nuancier
  - selinux

- name: apply selinux type to the wsgi file
  file: >
    dest=/var/www/nuancier.wsgi
    setype=httpd_sys_content_t
  tags:
  - nuancier
  - selinux
