---
#
# Setup askbot for ask.fedoraproject.org site. 
#
- name: install needed packages
  yum: pkg={{ item }} state=present
  with_items:
  - askbot
  - python-memcached
  - python-askbot-fedmsg
  - python-psycopg2
  - python-django-post_office
  - python-django-compressor
  - django-authopenid
  - django-celery
  tags:
  - ask
  - packages

# https://github.com/openid/python-openid/pull/76
- name: hotfix - copy over python-openid fixed messages
  copy: src="{{ files }}/hotfix/python-openid/fetchers.py" dest=/usr/lib/python2.6/site-packages/openid/fetchers.py
        owner=root group=root mode=0644
  notify:
  - restart apache
  tags:
  - ask
  - config
  - hotfix
  - python-openid

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

- name: set sebooleans so ask can use the gluster mount
  action: seboolean name=httpd_use_fusefs
                    state=true
                    persistent=true
  tags:
  - ask
  - selinux

- name: set sebooleans so ask can talk to the memcache
  action: seboolean name=httpd_can_network_memcache
                    state=true
                    persistent=true
  tags:
  - ask
  - selinux

- name: set sebooleans so ask can talk to fedmsg
  action: seboolean name=allow_httpd_sys_script_anon_write
                    state=true
                    persistent=true
  tags:
  - ask
  - selinux

- name: set sebooleans so ask can talk to fedmsg
  action: seboolean name=allow_ypbind
                    state=true
                    persistent=true
  tags:
  - ask
  - selinux

- name: install askbot settings.py template
  template: >
    src={{ item }} dest="/etc/askbot/sites/ask/config/settings.py"
    owner=apache group=fedmsg mode=0640
  with_items:
  - settings.py
  tags:
  - ask
  - config

- name: Install askbot.conf httpd config
  copy: >
    src=askbot.conf dest=/etc/httpd/conf.d/askbot.conf
    owner=root group=root mode=0644
  tags:
  - ask
  - files
  notify:
  - restart httpd

#
# we add this wsgi to handle ssl issues in stg
#
- name: Install askbot.wsgi httpd config
  copy: >
    src=askbot.wsgi dest=/usr/sbin/askbot.wsgi
    owner=root group=root mode=0755
  tags:
  - ask
  - files
  notify:
  - restart httpd

- name: Install askbot cron jobs
  copy: >
    src={{ item }} dest=/etc/cron.d/{{ item }}
    owner=root group=root mode=0644
  with_items: 
  - cron-ask-send-reminders
  - cron-post-office-send-mail
  - cron-delete-old-emails
  - cron-delete-unused-tags
  when: inventory_hostname.startswith('ask01')
  tags:
  - ask
  - files
  - cron

- name: check log file
  command: stat /var/log/askbot/askfedora.log
  register: logstat
  always_run: yes
  changed_when: "1 != 1"
  tags:
  - ask

- name: log ownership fix
  file: state=touch dest=/var/log/askbot/askfedora.log owner=apache group=apache
  when: logstat.rc == 1
  tags:
  - ask

- name: run collectstatic
  command: creates=/var/www/html/askbot/static python /etc/askbot/sites/ask/config/manage.py collectstatic --noinput
  tags:
  - ask
  - config

#- name: setup default skin link needed for askbot
#  file: state=link src=/usr/lib64/python2.6/site-packages/askbot/skins/default dest=/usr/lib64/python2.6/site-packages/askbot/static/default
#
#- name: setup admin skin link needed for askbot
#  file: state=link src=/usr/lib64/python2.6/site-packages/askbot/skins/admin dest=/usr/lib64/python2.6/site-packages/askbot/static/admin

#
# ?

- name: Disable Celery for good
  copy: >
    dest=/usr/lib/python2.6/site-packages/celeryconfig.py
    content="CELERY_ALWAYS_EAGER = True"
    owner=root group=root mode=0644
  tags:
  - ask
  - files
  - celery
  notify:
  - restart httpd

- name: HOTFIX askbot backends.py
  copy: >
    src=backends.py dest=/usr/lib/python2.6/site-packages/post_office/backends.py
    owner=root group=root mode=0644
  tags:
  - ask
  - files
  - hotfix
  notify:
  - restart httpd

#
# fedora favicon
#
- name: askbot favicon
  copy: >
    src=ask_favicon.ico dest=/var/lib/askbot/upfiles/ask/ask_favicon.ico
    owner=root group=root mode=0644
  tags:
  - ask
  - files
  - hotfix

#
# fixes login with facebook.
#

- name: HOTFIX askbot sanction-client.py
  copy: >
    src=sanction-client.py dest=/usr/lib/python2.6/site-packages/sanction/client.py
    owner=root group=root mode=0644
  tags:
  - ask
  - files
  - hotfix
  notify:
  - restart httpd

#
# fix for feedback
#
# this is not required for askbot 0.7.51 - diff == 0
- name: HOTFIX askbot/middleware/cancel.py
  copy: >
    src=cancel.py dest=/usr/lib/python2.6/site-packages/askbot/middleware/cancel.py
    owner=root group=root mode=0644
  tags:
  - ask
  - files
  - hotfix
  notify:
  - restart httpd
