- name: push packages out
  hosts: fedimg:fedimg_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"

  tasks:
  - name: clean all metadata {%if testing%}(with infrastructure-testing on){%endif%}
    command: yum clean all {%if testing%} --enablerepo=infrastructure-tags-stg {%endif%}
    check_mode: no

  - name: update fedimg packages from main repo
    package:
        name: ["python2-fedimg", "python2-libcloud", "python2-fedfind", "python2-toml", "python-vcrpy"]
        state: latest
    when: not testing

  - name: update fedimg packages from testing repo
    yum:
        name: [python2-fedimg", "python2-libcloud", "python2-fedfind", "python2-toml", "python-vcrpy"]
        state: latest
        enablerepo: infrastructure-tags-stg
    when: testing

- name: verify the backend and restart it
  hosts: fedimg:fedimg_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
    nagios: action=downtime minutes=60 service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.iad2.fedoraproject.org
    ignore_errors: true

  roles:
  - role: fedimg
    aws_keyname: fedimg-dev
    aws_keypath: /etc/pki/fedimg/fedimg-dev
    aws_pubkeypath: /etc/pki/fedimg/fedimg-dev.pub
    when: env == 'staging'
  - role: fedimg
    aws_keyname: releng-ap-northeast-1
    aws_keypath: /etc/pki/fedimg/fedimg-prod
    aws_pubkeypath: /etc/pki/fedimg/fedimg-prod.pub
    when: env != 'staging'

  post_tasks:
  - service: name="fedmsg-hub" state=restarted
  - name: tell nagios to unshush
    nagios: action=unsilence service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.iad2.fedoraproject.org
    ignore_errors: true
