- name: check/create instance
  hosts: hrf.cloud.fedoraproject.org
  user: root
  gather_facts: False

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

  tasks:
  - include: "{{ tasks }}/persistent_cloud.yml"

- name: provision instance
  hosts: hrf.cloud.fedoraproject.org
  user: root
  gather_facts: True

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

  tasks:
  - include: "{{ tasks }}/cloud_setup_basic.yml"

  handlers:
  - include: "{{ handlers }}/restart_services.yml"

- name: deploy hrf
  hosts: hrf.cloud.fedoraproject.org
  user: root
  gather_facts: True

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

  tasks:
    - name: install deps
      yum: state=present name={{ item }}
      with_items:
        - httpd
        - python-flask
        - python-fedmsg-meta-fedora-infrastructure
        - fedmsg
        - mod_wsgi
        - htop # not a dep, but handy
        - git
        - fail2ban

    - name: enable fail2ban and start it
      shell: chkconfig fail2ban on && service fail2ban start

    - name: clone the flask repo
      git: repo=git://github.com/fedora-infra/hrf.git dest=/srv/www/hrf accept_hostkey=true

    - name: enable port 80
      command: lokkit -p '80:tcp'
