- name: install limnoria package
  package: name={{ item }} state=present enablerepo=epel-testing
  with_items:
  - limnoria
  - supybot-fedora
  - supybot-koji
  - supybot-notify
  - supybot-pinglists
  - supybot-fedmsg
  - packagedb-cli
  - python-simplejson
  tags: supybot

- set_fact: botname={{ botnames[env] }}

- name: creating zodbot log dir
  file: path={{ item }} state=directory owner=daemon
  with_items:
  - /var/lib/{{ botname }}
  - /var/lib/{{ botname }}/conf
  - /var/lib/{{ botname }}/data
  - /var/lib/{{ botname }}/logs
  - /srv/web
  - /srv/web/meetbot
  tags: supybot

- name: create teams directory
  file: path=/srv/web/meetbot/teams state=directory owner=apache group=apache mode=0755
  tags: supybot

- name: create archives directory
  file: path=/srv/web/meetbot/archives state=directory owner=apache group=apache mode=0755
  tags: supybot

- name: setup meetings_by_team script
  copy: src=meetings_by_team.sh dest=/usr/local/bin/meetings_by_team.sh mode=755
  tags: supybot

- name: teams cron job
  cron: name=meetings-by-team hour="23" minute="0" user=apache job="/usr/local/bin/meetings_by_team.sh"
  tags: supybot

- name: setup archive script
  copy: src=archive.sh dest=/usr/local/bin/archive.sh mode=755
  tags: supybot

- name: teams cron job
  cron: name=archive hour="23" minute="30" user=apache job="/usr/local/bin/archive.sh >& /dev/null"
  tags: supybot

- name: setup meetbot.conf apache config
  copy: src=meetbot.conf dest=/etc/httpd/conf.d/meetbot.conf mode=644
  tags: supybot

- name: check the selinux context of the /srv/web/meetbot dir
  command: matchpathcon /srv/web/meetbot
  register: context
  check_mode: no
  changed_when: "1 != 1"
  tags:
  - config
  - selinux
  - meetbot
  - supybot

- name: /srv/web/meetbot file contexts
  command: semanage fcontext -a -t httpd_sys_content_t "/srv/web/meetbot(/.*)?"
  when: context.stdout.find('httpd_sys_content_t') == -1
  tags:
  - config
  - selinux
  - meetbot
  - supybot

- name: setup zodbot systemd service file (prod)
  copy: src=zodbot.service dest=/etc/systemd/system/zodbot.service
  when: env == "production"
  notify:
  - reload systemd
  tags:
  - config
  - supybot

- name: enable zodbot service (prod)
  service: name=zodbot state=started enabled=true
  when: env == "production"
  tags:
  - config
  - supybot

- name: setup ursabot systemd service file (stg)
  copy: src=ursabot.service dest=/etc/systemd/system/ursabot.service
  when: env == "staging"
  notify:
  - reload systemd
  tags:
  - config
  - supybot

- name: enable ursabot service (stg)
  service: name=ursabot state=started enabled=true
  when: env == "staging"
  tags:
  - config
  - supybot

- name: setup the SAR script for the meetbot logs
  copy: src=meetbot_sar.py dest=/usr/local/bin/meetbot_sar.py
        owner=root group=root mode=0700
  tags:
  - config
  - supybot
  - SAR
  - GDPR

