- name: Create the LinuxFR user
  user: name=linuxfr home=/data/dev/linuxfr state=present

- name: Clone the LinuxFR repository
  git: repo=git://github.com/nono/linuxfr.org.git dest=/data/dev/linuxfr/source

- name: Configure the Rails apps's database
  copy: src=linuxfr/database.yml dest=/data/dev/linuxfr/source/config/database.yml

- name: Configure the Rails apps's secrets
  copy: src=linuxfr/secret.yml dest=/data/dev/linuxfr/source/config/secret.yml

- name: Install the Rails app using Bundler
  command: bundle install chdir=/data/dev/linuxfr/source

- name: Setup ElasticSearch
  command: desi install chdir=/data/dev/linuxfr/source

- name: Setup the database
  command: rake db:setup chdir=/data/dev/linuxfr/source

- name: Flush the Redis database
  command: redis-cli flushdb

# This doesn't work because  undefined method `tire' for #<Class:0x00000005cdedf8> (NoMethodError)
#- name: Initialize indexes
#  command: ./script/rails r '[Diary, News, Page, Poll, Post, Tracker, WikiPage].each {|m| m.tire.index.refresh }'
#           chdir=/data/dev/linuxfr

- name: Create the LinuxFR user
  user: name=linuxfr home=/data/dev/linuxfr state=present

- name: Clone the LinuxFR repository
  git: repo=git://github.com/nono/linuxfr.org.git dest=/data/dev/linuxfr/source

- name: Configure the Rails apps's database
  copy: src=linuxfr/database.yml dest=/data/dev/linuxfr/source/config/database.yml

- name: Configure the Rails apps's secrets
  copy: src=linuxfr/secret.yml dest=/data/dev/linuxfr/source/config/secret.yml

- name: Install the Rails app using Bundler
  command: bundle install chdir=/data/dev/linuxfr/source

- name: Setup ElasticSearch
  command: desi install chdir=/data/dev/linuxfr/source

- name: Check if the database already exists
  command: rake db:version chdir=/data/dev/linuxfr/source
  ignore_errors: True
  register: db_version

- name: Setup the database
  command: rake db:setup chdir=/data/dev/linuxfr/source
  when: db_version|failed

- name: Migrate the database
  command: rake db:migrate chdir=/data/dev/linuxfr/source
  when: db_version|success

- name: Flush the Redis database
  command: redis-cli flushdb

# This doesn't work because  undefined method `tire' for #<Class:0x00000005cdedf8> (NoMethodError)
#- name: Initialize indexes
#  command: ./script/rails r '[Diary, News, Page, Poll, Post, Tracker, WikiPage].each {|m| m.tire.index.refresh }'
#           chdir=/data/dev/linuxfr

Add support for migrating the database if it is already set up.
Add support for migrating the database if it is already set up.

http://mxey.net/deploying-rails-with-ansible/
