# create a new notifs-backend server
# NOTE: should be used with --limit most of the time
# NOTE: make sure there is room/space for this server on the vmhost
# NOTE: most of these vars_path come from group_vars/mirrorlist or from hostvars

- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml"
  vars:
    myhosts: "notifs_backend:notifs_backend_stg"

- name: dole out the generic configuration
  hosts: notifs_backend:notifs_backend_stg
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  pre_tasks:
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"

  roles:
  - base
  - rkhunter
  - hosts
  # The proxies don't actually need to talk to these hosts so we won't bother
  # putting them on the vpn.
  #- { role: openvpn/client,
  #    when: env != "staging" }
  - ipa/client
  - nagios_client
  - collectd/base
  - fedmsg/base
  - role: keytab/service
    owner_user: fedmsg
    owner_group: fedmsg
    service: fedmsg-hub-3
  # Set up for fedora-messaging
  - role: rabbit/user
    username: "notifs-backend{{ env_suffix }}"
    sent_topics: ^org\.fedoraproject\.{{ env_short }}\.(fmn|logger)\..*
  - sudo

  tasks:
  - import_tasks: "{{ tasks_path }}/motd.yml"

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

- name: dole out the service-specific config
  hosts: notifs_backend:notifs_backend_stg
  user: root
  gather_facts: True

  pre_tasks:
  - name: tell nagios to shush w.r.t. the backend since it usually complains
    nagios: action=downtime minutes=25 service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.iad2.fedoraproject.org
    ignore_errors: true
    tags:
    - fedmsgdconfig
    - notifs/backend

  roles:
  - fedmsg/hub
  - rabbitmq
  - memcached
  - notifs/backend
  - role: collectd/fedmsg-service
    process: fedmsg-hub
    when: inventory_hostname.startswith('notifs-backend01.iad2')

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"
