- name: check/create instance
  hosts: 209.132.184.144
  user: root
  gather_facts: False

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

  tasks:
  - include: $tasks/persistent_cloud.yml
  - include: $tasks/growroot_cloud.yml

- name: provision instance
  hosts: 209.132.184.144
  user: root
  gather_facts: True

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

  tasks:
  - include: $tasks/cloud_setup_basic.yml
  - name: mount up disk of copr fe
    action: mount name=/srv/copr-fe src='LABEL=copr-fe' fstype=ext4 state=mounted

  - name: mount up bind mount for postgres
    action: mount src=/srv/copr-fe/pgsqldb name=/var/lib/pgsql fstype=auto opts=bind state=mounted

  - name: install copr-fe pkgs
    action: yum state=installed name=$item
    with_items:
    - httpd
    - mod_wsgi
    - postgresql
    - bash-completion
    - postgresql-server
    - git

  - name: copy apache files to conf.d
    action: copy src=$files/copr/fe/httpd/$item dest=/etc/httpd/conf.d/$item
    with_items:
    - coprs.conf
    - welcome.conf

   
  - name: start services
    action: service state=running enabled=yes name=$item
    with_items:
    - httpd
    - postgresql


  # open up ports (22, 80, 443)
  - name: poke holes in the firewall
    action: command lokkit $item
    with_items:
    - --service=ssh
    - --service=https
    - --service=http



  handlers:
  - include: $handlers/restart_services.yml
