---
# Configuration for the notifications consumer

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - koji
  - fedmsg
  - python-paramiko
  - python-fedimg
  - python-libcloud
  - python-fedimg
  - python-boto3
  tags:
  - fedimg

- name: install extra packages in staging
  package: name={{ item }} state=present
  with_items:
  - euca2ools
  tags:
  - fedimg

- name: copy manual trigger script
  copy: >
    src=trigger_upload.py
    dest=/usr/local/bin/trigger_upload.py
    mode=0755
  tags:
  - fedimg

- name: copy manual partial trigger script
  copy: >
    src=partial_upload.py
    dest=/usr/local/bin/partial_upload.py
    mode=0755
  tags:
  - fedimg

- name: copy base configuration
  template: >
    src=fedimg-conf.toml dest=/etc/fedimg/fedimg-conf.toml
    owner=fedmsg group=fedmsg mode=0700
  notify:
  - restart fedmsg-hub
  tags:
  - fedimg

- name: copy the euca2ools configuration file
  template: >
      src=fedimg-euca-conf.ini dest=/etc/euca2ools/conf.d/fedimg-euca-conf.ini
      owner=fedmsg group=fedmsg mode=0700
  notify:
  - restart fedmsg-hub
  tags:
  - fedimg

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

- name: make pki directory
  file: dest=/etc/pki/fedimg/ state=directory
        owner=fedmsg group=fedmsg mode=0500
  tags:
  - fedimg

- name: copy keys into pki directory for staging
  copy: src={{private}}/files/fedimg/{{item}} dest=/etc/pki/fedimg/{{item}}
        owner=fedmsg group=fedmsg mode=0400
  with_items:
  - fedimg-dev
  - fedimg-dev.pub
  notify:
  - restart fedmsg-hub
  when: env == "staging"
  tags:
  - fedimg

- name: copy keys into pki directory for production
  copy: src={{private}}/files/fedimg/{{item}} dest=/etc/pki/fedimg/{{item}}
        owner=fedmsg group=fedmsg mode=0400
  with_items:
  - fedimg-prod
  - fedimg-prod.pub
  notify:
  - restart fedmsg-hub
  when: env != "staging"
  tags:
  - fedimg

- name: ensure the fedmsg user has a homedir for cron to work in
  file: >
    state=directory
    path=/usr/share/fedmsg
    mode=700
    owner=fedmsg
    group=fedmsg
  tags:
  - cron
  - fedimg

- name: ensure fedimg cron directories exist
  file: >
    state=directory
    path={{ item }}
    mode=755
    owner=root
  with_items:
  - /usr/share/fedimg/cronjobs/
  - /etc/cron.d/
  tags:
  - cron
  - fedimg

- name: copy the releng script to purge ami to test
  copy: >
    src=clean-amis.py dest=/usr/local/bin/clean-amis.py
    owner=fedmsg group=fedmsg mode=0700
  tags:
  - scripts
  - fedimg
