---
# Configuration for the notifications consumer

#- name: install needed packages
#  package: name={{ item }} state=present
#  with_items:
#  - python-fmn
#  - python-psycopg2
#  - libsemanage-python
#  - python-gssapi
#  - python-requests-gssapi
#  # Needed to produce nice long emails about koji builds
#  - koji
#  when:
#    inventory_hostname.startswith('notifs-backend01.iad2')
#  tags:
#  - notifs
#  - notifs/backend

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - python3-fmn
  - python-psycopg2
  - python3-libsemanage
  - python3-gssapi
  - python3-pylibmc
  - python3-requests-gssapi
  # Needed to produce nice long emails about koji builds
  - koji
    #  when:
    #inventory_hostname.startswith('notifs-backend02') or env == 'staging'
  tags:
  - notifs
  - notifs/backend

- name: ensure systemd drop-in directory exists
  file: >
    dest=/etc/systemd/system/fedmsg-hub-3.service.d
    state=directory
  tags:
  - notifs
  - notifs/backend
    #  when:
    #inventory_hostname.startswith('notifs-backend02') or env == 'staging'

- name: ensure memcached is running
  systemd:
    state: started
    name: memcached

- name: install fedmsg-hub-3 systemd drop-in
  template: src=override.conf.j2 dest=/etc/systemd/system/fedmsg-hub-3.service.d/override.conf owner=root group=root mode=644
  notify:
  - reload systemd
  tags:
  - notifs
  - notifs/backend
    #  when:
    #inventory_hostname.startswith('notifs-backend02') or env == 'staging'

- name: hotfix python3-moksha-hub
  copy: >
    src=consumer.py dest=/usr/lib/python3.10/site-packages/moksha/hub/api/consumer.py
    owner=root group=root mode=0644
  notify:
  - restart fedmsg-hub
  tags:
  - notifs
  - notifs/backend
    #  when:
    #inventory_hostname.startswith('notifs-backend02') or env == 'staging'

- name: copy database configuration
  template: >
    src={{ item }} dest=/etc/fedmsg.d/{{ item }}
    owner=fedmsg group=fedmsg mode=0600
  with_items:
  - fmn.consumer.py
  notify:
  - restart fedmsg-hub
  tags:
  - notifs
  - notifs/backend

#- name: Hotfix fmn for fasjson
#  copy: >
#    src=fasjson-port/{{ item }} dest=/usr/lib/python2.7/site-packages/fmn/{{ item }}
#  with_items:
#  - consumer.py
#  - fasjson_client.py
#  - fmn_fasshim.py
#  - tasks.py
#  - util.py
#  when:
#    inventory_hostname.startswith('notifs-backend01.iad') or env != 'staging'
#  tags:
#  - notifs
#  - notifs/backend

- name: Install fmn SSE configuration
  template: >
    src={{ item }} dest=/etc/fedmsg.d/{{ item }}
    owner=fedmsg group=fedmsg mode=0600
  with_items:
  - fmn.sse.py
#  when: env == "staging"
  notify:
  - restart fedmsg-hub
  tags:
  - notifs
  - notifs/backend

- name: copy the alembic configuration for DBAs
  template: >
    src=alembic.ini dest=/usr/share/fmn/alembic.ini
    owner=root group=sysadmin-dba mode=0660
  notify:
  - restart fedmsg-hub
  tags:
  - notifs
  - notifs/backend

- name: copy over admin utility scripts
  copy: src=bin/{{ item }} dest=/usr/local/bin/{{ item }} owner=root group=root mode=0755
  with_items:
  - fmn-create-account
  - fmn-disable-account
  tags:
  - notifs
  - notifs/backend

- name: override the default syslog logrotate file
  copy: src=syslog-logrotate dest=/etc/logrotate.d/rsyslog
  tags:
  - notifs
  - notifs/backend

- name: start the workers and the backend
  service: name={{item}} enabled=yes state=started
  with_items:
  - fmn-backend@1
  - fmn-worker@1
  - fmn-worker@2
  - fmn-worker@3
  - fmn-worker@4
  - fmn-worker@5
  - fmn-worker@6
  - fmn-worker@7
  - fmn-worker@8
  - fmn-worker@9
  - fmn-worker@10
  - fmn-worker@11
  - fmn-worker@12
  - fmn-worker@13
  - fmn-worker@14
  - fmn-worker@15
  - fmn-worker@16
  - fmn-worker@17
  - fmn-worker@18
  - fmn-worker@19
  - fmn-worker@20
  - fmn-worker@21
  - fmn-worker@22
  - fmn-worker@23
  - fmn-worker@24
  - fmn-celerybeat
  tags:
  - notifs
  - notifs/backend
