---
# Configuration for the mote webapp

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - mote
  - memcached
  tags:
  - packages
  - mote

- name: set the memcached sysconfig file
  copy:
    src: memcached.sysconfig
    dest: /etc/sysconfig/memcached
  tags:
  - mote
  notify:
  - restart memcached

- name: make systemd override dir
  file:
    state: directory
    path: /etc/systemd/system/memcached.service.d
    mode: 0755
    owner: root
    group: root
  tags:
  - mote

- name: make systemd override config
  copy:
    src: memcached.override
    dest: /etc/systemd/system/memcached.service.d/override.conf
  tags:
  - mote
  notify:
  - reload systemd
  - restart memcached

- meta: flush_handlers

- name: start memcached
  service:
    state: started
    enabled: yes
    name: memcached
  tags:
  - mote

- name: replace the mote 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: config.py, location: /etc/mote }
  - { file: mote.conf, location: /etc/httpd/conf.d }
  - { file: mote.wsgi, location: /usr/share/mote }
  - { file: category_mappings.json, location: /usr/share/mote }
  - { file: name_mappings.json, location: /usr/share/mote }
  tags:
  - config
  - mote
  notify:
  - nuke mote json cache
  - restart apache

- name: Create /usr/share/httpd/.local for mote-updater to store the fedmsg CRL
  file: dest=/usr/share/httpd/.local owner=apache group=apache state=directory
  tags:
  - mote

- name: start mote-updater service
  service: name=mote-updater state=started enabled=yes
  tags:
  - services
  - mote

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

- name: apply selinux type to meetbot files
  file: >
    dest=/srv/web/meetbot/
    setype=httpd_sys_content_t
    state=directory
    recurse=yes
  tags:
  - mote
  - selinux

- name: set sebooleans so apache can use memcached
  seboolean: name=httpd_can_network_memcache
                    state=true
                    persistent=true
  tags:
  - mote
  - selinux

- name: set sebooleans so apache can use nfs
  seboolean: name=httpd_use_nfs
                    state=true
                    persistent=true
  tags:
  - mote
  - selinux

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

- name: apply selinux type to the name mappings file
  file: >
    dest=/usr/share/mote/name_mappings.json
    setype=httpd_sys_content_t
  notify:
  - nuke mote json cache
  tags:
  - mote
  - selinux

- name: apply selinux type to the category mappings file
  file: >
    dest=/usr/share/mote/category_mappings.json
    setype=httpd_sys_content_t
  notify:
  - nuke mote json cache
  tags:
  - mote
  - selinux
