---

- hosts: all
  user: vagrant
  sudo: yes
  vars:
    root_db_password: CGRateS.org

  tasks:
    - name: install dependency
      apt: pkg={{ item }} state=latest
      with_items:
        - git
        - redis-server
        - mysql-server
        - python-mysqldb
      
    - name: add freeswitch gpg key
      command: gpg --keyserver pool.sks-keyservers.net --recv-key D76EDC7725E010CF
      
    - name: add freeswitch apt key
      shell: gpg -a --export D76EDC7725E010CF | sudo apt-key add -

    - name: add freeswitch apt repo
      apt_repository: repo='deb http://files.freeswitch.org/repo/deb/debian/ wheezy main' state=present
      
    - name: install freeswitch
      apt: pkg={{ item }} update_cache=yes state=latest
      with_items:
        - freeswitch-meta-vanilla
        - freeswitch-mod-json-cdr

    - name: add cgrates apt-key
      apt_key: url=http://apt.itsyscom.com/conf/cgrates.gpg.key state=present

    - name: add cgrates repo
      apt_repository: repo='deb http://apt.itsyscom.com/debian wheezy main' state=present

    - name: install cgrates
      apt: pkg=cgrates update_cache=yes state=latest

    - name: update mysql root password for root account
      mysql_user: name=root host=localhost password={{ root_db_password }}

    - name: copy .my.cnf
      template: src=my.cnf dest=/root/.my.cnf mode=0600

    - name: setup database tables
      shell: chdir=/usr/share/cgrates/storage/mysql ./setup_cgr_db.sh root {{ root_db_password }} localhost
    

