---
- name: Set up environment in order to run call tests for Freeswitch
  hosts: all
  tasks:
    - name: Install freeswitch
      ansible.builtin.import_role:
        name: ../../roles/freeswitch
    - name: Install Go
      ansible.builtin.import_role:
        name: ../../roles/go

    - name: Install and config CGRateS
      ansible.builtin.import_role:
        name: ../../roles/cgrates
      vars:
        cgrates_dbs:
          - mysql
        cgrates_dependencies:
          - git
          - redis-server
          - mariadb-server

    - name: Unzip FreeSWITCH config
      become: yes
      shell: 'sudo tar -xvf freeswitch_conf.tar.gz'
      args:
        chdir: '{{ cgrates_dir }}/data/tutorial_tests/fs_evsock/freeswitch/etc'

    - name: Unzip FreeSWITCH config 2
      become: yes
      shell: 'sudo tar -xvf freeswitch_conf.tar.gz'
      args:
        chdir: '{{ cgrates_dir }}/data/tutorials/fs_evsock/freeswitch/etc'

    - name: Update internal.xml with the correct IP
      ansible.builtin.replace:
        path: '{{ cgrates_dir }}/data/tutorial_tests/fs_evsock/freeswitch/etc/freeswitch/sip_profiles/internal.xml'
        regexp: '192\.168\.56\.203'
        replace: '{{ ansible_host }}'

    - name: Remove FreeSWITCH default config from /etc/freeswitch
      become: yes
      shell: 'sudo rm -rf *'
      args:
        chdir: /etc/freeswitch

    - name: Copy our custom config for FreeSWITCH in /etc/freeswitch
      become: yes
      shell: 'sudo cp -r {{ cgrates_dir }}/data/tutorial_tests/fs_evsock/freeswitch/etc/freeswitch/* /etc/freeswitch'
      args:
        chdir: /etc/freeswitch

    - name: Configure PJSUA
      ansible.builtin.import_role:
        name: ../../roles/pjsua
      vars:
        pjsua_version: '2.9'
