--- 
- hosts: local
  vars:
    root_dir: /vagrant/registry
  tasks:

  - name: ensure apt dependencies
    apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=3600
    sudo: yes
    with_items:
    - git
    - htop
    - vim 
    - python-virtualenv
    tags: install
   
  - name: make flask app directories
    file: path={{ item }} state=directory
    with_items:
    - registry
    - registry/app
    - registry/tmp
    tags: install

  - name: create virualenv
    command: virtualenv flask chdir={{ root_dir }}
    tags: install

  - name: ensure pip dependencies
    pip: name={{ item.name }} version={{ item.ver }} virtualenv=flask chdir={{ root_dir }}
    with_items:
    - { name: flask, ver: 0.9 }
    - { name: flask-mail, ver: 0.7.6 } 
    - { name: sqlalchemy, ver: 0.7.9 }
    - { name: flask-sqlalchemy, ver: 0.16 }
    - { name: flask-whooshalchemy, ver: 0.54a }
    - { name: flask-wtf, ver: 0.8.4 }
    - { name: pytz, ver: 2013b }
    - { name: flask-babel, ver: 0.8 }
    tags: install
  - name: ensure pip dependencies
    pip: name={{ item.name }} virtualenv=/vagrant/flask
    with_items:
    - { name: sqlalchemy-migrate, ver: }
    - { name: flask-login, ver: }
    - { name: flask-openid, ver: }
    - { name: flup, ver: }
    tags: install
  
  - name: deploy flask app
    #local_action: command rsync -a files/app/ {{ inventory_hostname }}:{{ root_dir }}/app
    local_action: command rsync -a files/app/ {{ root_dir }}/app
    tags: deploy
  - name: deply flask run.py
    copy: src=files/run.py dest={{ root_dir }}/run.py mode=0755
    tags: deploy

  handlers:
