---
# Configuration for the Fedora Notifications webapp

- name: install needed packages
  dnf: pkg={{ item }} state=present
  with_items:
  - autocloud-common
  - autocloud-backend
  - tunir
  - fedfind
  - python2-fedfind
  - python-sqlalchemy
  - python-sqlalchemy-utils
  - libsemanage-python
  - libselinux-python
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: Check for the existance of a 'tunirports' redis entry
  command: redis-cli --scan --pattern tunirports
  changed_when: False
  register: tunirports
  check_mode: no
  tags:
  - autocloud
  - autocloud/backend


- name: copy autocloud backend configuration
  template: >
    src={{ item }} dest=/etc/autocloud/{{ item }}
    owner=root group=fedmsg mode=0640
  with_items:
  - autocloud.cfg
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: copy autocloud fedmsg configuration
  template: >
    src={{ item }} dest=/etc/fedmsg.d/{{ item }}
    owner=root group=fedmsg mode=0640
  with_items:
  - autocloud.py
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: install libvirt and vagrant-libvirt for the libvirt host
  dnf: pkg={{ item }} state=present
  with_items:
  - libvirt
  - vagrant-libvirt
  when: autocloud_specialization == 'libvirt'
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: install libvirt for the aarch64 host
  dnf: pkg={{ item }} state=present
  with_items:
  - libvirt
  when: autocloud_specialization == 'aarch64'
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend


- name: Setup virtualbox requirements where needed
  copy: src=virtualbox.repo dest=/etc/yum.repos.d/virtualbox.repo
  when: autocloud_specialization == 'virtualbox'
  tags:
  - autocloud
  - autocloud/backend

- name: install virtualbox basics where needed
  dnf: pkg={{ item }} state=present
  with_items:
  - VirtualBox-4.3
  - kernel-devel
  - gcc
  - vagrant
  register: virtualbox_installed
  check_mode: no
  when: autocloud_specialization == 'virtualbox' and inventory_hostname == 'autocloud-libvirt-vbox.phx2.fedoraproject.org'
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: install virtualbox basics where needed
  dnf: pkg={{ item }} state=present
  with_items:
  - VirtualBox-5.1
  - kernel-devel
  - gcc
  - vagrant
  register: virtualbox_installed
  check_mode: no
  when: autocloud_specialization == 'virtualbox' and inventory_hostname == 'autocloud-libvirt-vbox2.phx2.fedoraproject.org'
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: setup vbox if it was just installed.
  command: /etc/init.d/vboxdrv setup
  when: virtualbox_installed is changed
  notify:
  - restart fedmsg-hub
  - restart autocloud
  tags:
  - autocloud
  - autocloud/backend

- name: Copy the correct tunir job details
  copy: src=fedora.txt dest=/etc/autocloud/fedora.txt
  tags:
  - autocloud
  - autocloud/backend
  - autocloud/backend/tests

- name: Set up a cronjob to run kill_vagrant every so often..
  copy: src=kill_vagrant.cron dest=/etc/cron.d/kill_vagrant.cron
  tags:
  - cron
  - autocloud
  - autocloud/backend

- name: start autocloud
  service: name=autocloud enabled=yes state=started
  tags:
  - autocloud
  - autocloud/backend

#
# Install hotfix to ignore new architectures
# See PR - https://github.com/kushaldas/autocloud/pull/62/
#
- name: hotfix - copy over consumer files
  copy: src='{{ files }}/{{ item.src }}' dest={{ item.dest }}
  with_items:
  - { src: 'hotfix/autocloud/consumer.py', dest: '/usr/lib/python2.7/site-packages/autocloud' }
  notify:
  - restart fedmsg-hub
  tags:
  - autocloud
  - hotfix
