---
# Configuration for the fedbadges consumer

- name: install needed packages
  yum: pkg={{ item }} state=present
  with_items:
  - python-fedbadges
  - python-psycopg2
  - git
  - python-dogpile-cache
  tags:
  - packages
  - badges
  - badges/backend

- name: copy database configuration
  template: >
    src={{ item }} dest="/etc/fedmsg.d/{{ item }}"
    owner=fedmsg group=fedmsg mode=0600
  with_items:
  - datanommer.py
  - badges-awarder.py
  tags:
  - config
  - badges
  - badges/backend
  notify:
  - restart fedmsg-hub

- name: copy alembic configuration
  template: >
    src=alembic.ini dest=/usr/share/tahrir_api/alembic.ini
    owner=fedmsg group=fedmsg mode=0600
  tags:
  - config
  - badges
  - badges/backend

- name: make badge definition directory
  file: >
    path=/usr/share/badges/rules
    state=directory
    owner=fedmsg group=fedmsg mode=0755
  tags:
  - config
  - badges
  - badges/backend

- name: copy over all our badge definitions
  copy: >
    src=/srv/web/infra/badges/rules/
    dest=/usr/share/badges/rules/
    owner=fedmsg group=fedmsg mode=0644
  tags:
  - config
  - badges
  - badges/backend
  notify:
  - restart fedmsg-hub

- name: ensure the fedmsg user has a homedir for cron to work
  file: >
    state=directory
    path=/usr/share/fedmsg
    mode=700
    owner=fedmsg
    group=fedmsg
  when: env != "staging"
  tags:
  - config
  - cron
  - badges
  - badges/backend

- name: ensure badges cron directories exist
  file: >
    state=directory
    path={{ item }}
    mode=755
    owner=root
  when: env != "staging"
  with_items:
  - /usr/share/badges/cronjobs/
  - /etc/cron.d/
  tags:
  - config
  - cron
  - badges
  - badges/backend

- name: oldschool badge award scripts
  copy: >
    src="cron/{{ item }}"
    dest="/usr/share/badges/cronjobs/{{ item }}"
    owner=fedmsg
    mode=744
  when: env != "staging"
  with_items:
  - award-oldschool-badges
  - award-libravatar-badge
  - award-flock-paparazzi-badge
  - award-mirror-badge
  - award-lifecycle-badges
  - award-badges-dev-badge
  tags:
  - config
  - cron
  - badges
  - badges/backend

- name: oldschool badge award cronjobs
  copy: >
    src="cron/{{ item }}.cron"
    dest="/etc/cron.d/{{ item }}"
    owner=root
    mode=644
  when: env != "staging"
  with_items:
  - award-oldschool-badges
  - award-libravatar-badge
  - award-flock-paparazzi-badge
  - award-mirror-badge
  - award-lifecycle-badges
  - award-badges-dev-badge
  tags:
  - config
  - cron
  - badges
  - badges/backend

- name: copy creds for the flock paparazzi cronjob
  template: >
    src=flock-paparazzi.ini
    dest=/etc/flock-paparazzi.ini
    owner=fedmsg group=fedmsg mode=0600
  tags:
  - config
  - cron
  - badges
  - badges/backend

- name: logrotate for badge award cronjobs
  copy: >
    src=cron/cron-badges-logrotate
    dest=/etc/logrotate.d/cron-badges-logrotate
    owner=root
    mode=644
  tags:
  - config
  - cron
  - badges
  - badges/backend

- name: copy over the badge-admin one-off scripts
  copy: >
    src={{ item }}
    dest="/usr/local/bin/{{ item }}"
    owner=root
    group=sysadmin-badges
    mode=750
  with_items:
  - award-badge
  - revoke-badge
  - grant-authorization
  - get-badges-person-id
  tags:
  - scripts
  - badges
  - badges/backend
