- name: push packages out
  hosts: bugyou:bugyou-stg
  user: root
  vars_files: 
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  vars:
    testing: False
  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

  tasks:
  - name: clean all metadata {%if testing%}(with infrastructure-testing on){%endif%}
    command: yum clean all {%if testing%} --enablerepo=infrastructure-tags-stg {%endif%}
    always_run: yes
  - name: yum update bugyou packages from main repo
    yum: name="bugyou*" state=latest
    when: not testing
  - name: yum update bugyou packages from testing repo
    yum: name="bugyou*" state=latest enablerepo=infrastructure-tags-stg
    when: testing

- name: verify the backends, stop them, and then upgrade the db
  hosts: bugyou:bugyou-stg
  user: root
  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"

  pre_tasks:
  - name: tell nagios to shush w.r.t. the backend
    nagios: action=downtime minutes=15 service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.phx2.fedoraproject.org
    ignore_errors: true

  roles:
  - bugyou/backend

  tasks:
  - name: Stop the fedmsg-hub backend
    service: name="fedmsg-hub" state=stopped
  - name: Stop the bugyou controller backend
    service: name="bugyou-cntrl" state=stopped

  - name: And... start the bugyou controller backend again
    service: name="bugyou-cntrl" state=started
  - name: And... start the fedmsg-hub backend again
    service: name="fedmsg-hub" state=started

  post_tasks:
  - name: tell nagios to unshush w.r.t. the backend
    nagios: action=unsilence service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.phx2.fedoraproject.org
    ignore_errors: true

