mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add ansible for installing and configuration CGRateS with FreeSWITCH
This commit is contained in:
committed by
Dan Christian Bogos
parent
76dc53a720
commit
c59721f4f2
69
data/ansible/calls/freeswitch/cgrates.yaml
Normal file
69
data/ansible/calls/freeswitch/cgrates.yaml
Normal file
@@ -0,0 +1,69 @@
|
||||
---
|
||||
- name: install glide
|
||||
shell: go get -u github.com/Masterminds/glide
|
||||
environment:
|
||||
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin"
|
||||
|
||||
- name: create cgrates directory
|
||||
become: yes
|
||||
file:
|
||||
state: directory
|
||||
mode: 'u=rwx,go=rx'
|
||||
owner: "{{ gouser }}"
|
||||
group: "{{ gouser }}"
|
||||
dest: '{{ cgrates_dir }}'
|
||||
become_user: "{{ gouser }}"
|
||||
|
||||
- name: git clone cgrates
|
||||
git:
|
||||
repo: https://github.com/cgrates/cgrates.git
|
||||
dest: '{{ cgrates_dir }}'
|
||||
update: yes
|
||||
force: yes
|
||||
become: yes
|
||||
become_user: "{{ gouser }}"
|
||||
|
||||
# Before installing glide make sure vendor don't exist
|
||||
- name: Remove vendor
|
||||
shell: "sudo rm -rf {{ cgrates_dir }}/vendor"
|
||||
ignore_errors: true
|
||||
|
||||
- name: glide install
|
||||
shell: '{{ golang_gopath }}/bin/glide install'
|
||||
environment:
|
||||
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin"
|
||||
args:
|
||||
chdir: '{{ cgrates_dir }}'
|
||||
|
||||
- name: build cgrates
|
||||
shell: "sh {{ cgrates_dir }}/build.sh"
|
||||
environment:
|
||||
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
||||
args:
|
||||
chdir: '{{ cgrates_dir }}'
|
||||
|
||||
- name: symbol link
|
||||
become: yes
|
||||
file:
|
||||
src: "{{ cgrates_dir }}/data"
|
||||
dest: "/usr/share/cgrates"
|
||||
state: link
|
||||
|
||||
- name: symbol link
|
||||
become: yes
|
||||
file:
|
||||
src: "{{ golang_gopath }}/bin/cgr-engine"
|
||||
dest: "/usr/bin/cgr-engine"
|
||||
state: link
|
||||
# post install
|
||||
- name: post install mysql
|
||||
become: yes
|
||||
command: 'sh {{ cgrates_dir }}/data/storage/mysql/setup_cgr_db.sh root CGRateS.org localhost'
|
||||
args:
|
||||
chdir: '{{ cgrates_dir }}/data/storage/mysql/'
|
||||
|
||||
- name: post install postgres2
|
||||
become: yes
|
||||
command: 'sh {{ cgrates_dir }}/data/storage/postgres/create_db_with_users.sh'
|
||||
args:
|
||||
chdir: '{{ cgrates_dir }}/data/storage/postgres/'
|
||||
109
data/ansible/calls/freeswitch/go.yaml
Normal file
109
data/ansible/calls/freeswitch/go.yaml
Normal file
@@ -0,0 +1,109 @@
|
||||
---
|
||||
- name: create gopath directory
|
||||
file:
|
||||
state: directory
|
||||
mode: 'u=rwx,go=rx'
|
||||
dest: '{{ golang_gopath }}'
|
||||
|
||||
- name: create download directory
|
||||
file:
|
||||
state: directory
|
||||
mode: 'u=rwx,go=rx'
|
||||
dest: '{{ golang_download_dir }}'
|
||||
|
||||
- name: download Go language SDK
|
||||
get_url:
|
||||
url: '{{ golang_mirror }}/{{ golang_redis_filename }}'
|
||||
dest: '{{ golang_download_dir }}/{{ golang_redis_filename }}'
|
||||
mode: 'u=rw,go=r'
|
||||
|
||||
- name: create Go language SDK installation directory
|
||||
become: yes
|
||||
file:
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: 'u=rwx,go=rx'
|
||||
dest: '{{ golang_install_dir }}'
|
||||
|
||||
- name: install Go language SDK
|
||||
become: yes
|
||||
unarchive:
|
||||
src: '{{ golang_download_dir }}/{{ golang_redis_filename }}'
|
||||
remote_src: yes
|
||||
extra_opts: '--strip-components=1'
|
||||
dest: '{{ golang_install_dir }}'
|
||||
owner: root
|
||||
group: root
|
||||
creates: '{{ golang_install_dir }}/bin'
|
||||
|
||||
# Set Go language SDK environment variables
|
||||
- name: make sure /etc/profile.d exists
|
||||
become: yes
|
||||
file:
|
||||
path: /etc/profile.d
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: 'u=rwx,go=rx'
|
||||
|
||||
- name: export Go language SDK environment variables
|
||||
become: yes
|
||||
template:
|
||||
src: golang.sh.j2
|
||||
dest: /etc/profile.d/golang.sh
|
||||
owner: root
|
||||
group: root
|
||||
mode: 'u=rw,go=r'
|
||||
|
||||
- name: Export GOROOT for root
|
||||
become: yes
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export GOROOT='{{ golang_install_dir }}'
|
||||
insertafter: last
|
||||
|
||||
- name: Add GOROOT to PATH for root
|
||||
become: yes
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export PATH=$PATH:$GOROOT/bin
|
||||
insertafter: last
|
||||
|
||||
- name: Export GOPATH for root
|
||||
become: yes
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export GOPATH='{{ golang_gopath }}'
|
||||
insertafter: last
|
||||
|
||||
- name: Add GOPATH to PATH for root
|
||||
become: yes
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export PATH=$PATH:$GOPATH/bin
|
||||
insertafter: last
|
||||
|
||||
- name: Export GOROOT
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export GOROOT='{{ golang_install_dir }}'
|
||||
insertafter: last
|
||||
|
||||
- name: Add GOROOT to PATH
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export PATH=$PATH:$GOROOT/bin
|
||||
insertafter: last
|
||||
|
||||
- name: Export GOPATH
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export GOPATH='{{ golang_gopath }}'
|
||||
insertafter: last
|
||||
|
||||
- name: Add GOPATH to PATH
|
||||
lineinfile:
|
||||
path: ~/.bashrc
|
||||
line: export PATH=$PATH:$GOPATH/bin
|
||||
insertafter: last
|
||||
12
data/ansible/calls/freeswitch/golang.sh.j2
Normal file
12
data/ansible/calls/freeswitch/golang.sh.j2
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
#!/bin/sh
|
||||
|
||||
{{ ansible_managed | comment('plain') }}
|
||||
|
||||
export GOROOT='{{ golang_install_dir }}'
|
||||
export PATH=$PATH:$GOROOT/bin
|
||||
|
||||
{% if golang_gopath not in (None, '') %}
|
||||
export GOPATH="{{ golang_gopath }}"
|
||||
export PATH=$PATH:$GOPATH/bin
|
||||
{% endif %}
|
||||
108
data/ansible/calls/freeswitch/main.yaml
Normal file
108
data/ansible/calls/freeswitch/main.yaml
Normal file
@@ -0,0 +1,108 @@
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
###############################################################
|
||||
##################### Golang Vars #############################
|
||||
###############################################################
|
||||
# Go language SDK version number
|
||||
golang_version: '1.12.7'
|
||||
# Mirror to download the Go language SDK redistributable package from
|
||||
golang_mirror: 'https://storage.googleapis.com/golang'
|
||||
# Base installation directory the Go language SDK distribution
|
||||
golang_install_dir: '/usr/local/go'
|
||||
# Directory to store files downloaded for Go language SDK installation
|
||||
golang_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}"
|
||||
# Location for GOPATH environment variable
|
||||
golang_gopath: "/home/{{ gouser }}/go"
|
||||
# Filename of Go language SDK redistributable package
|
||||
golang_redis_filename: 'go{{ golang_version }}.linux-amd64.tar.gz'
|
||||
###############################################################
|
||||
# CGRateS location
|
||||
cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates"
|
||||
|
||||
rootUser : root
|
||||
|
||||
freeswitch_packages:
|
||||
- freeswitch-meta-all
|
||||
- freeswitch-mod-json-cdr
|
||||
|
||||
dependencies:
|
||||
- build-essential
|
||||
- git
|
||||
- redis-server
|
||||
- mariadb-server
|
||||
- postgresql
|
||||
- postgresql-contrib
|
||||
- python-dev
|
||||
- gcc
|
||||
- make
|
||||
- binutils
|
||||
- libasound2-dev
|
||||
|
||||
customPath: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
|
||||
|
||||
remote_user: cgrates
|
||||
tasks:
|
||||
###########################################################################################################################
|
||||
# install dependencies
|
||||
- name: Install dependencies
|
||||
become: yes
|
||||
apt: name={{ dependencies }} state=present
|
||||
|
||||
- name: Add key for freeswitch
|
||||
become: yes
|
||||
apt_key: url=https://files.freeswitch.org/repo/deb/debian-release/fsstretch-archive-keyring.asc state=present
|
||||
|
||||
- name: Add FreeSwitch apt repository (1.8) (Debian 8/Jessie)
|
||||
become: yes
|
||||
apt_repository:
|
||||
repo: deb http://files.freeswitch.org/repo/deb/debian-release/ stretch main
|
||||
state: present
|
||||
filename: 'freeswitch'
|
||||
|
||||
# Install FreeSwitch
|
||||
- name: Install FreeSwitch
|
||||
become: yes
|
||||
apt: name={{ freeswitch_packages }} state=latest
|
||||
|
||||
###########################################################################################################################
|
||||
# Install Golang
|
||||
- name: install unarchive dependencies (zypper)
|
||||
become: yes
|
||||
zypper:
|
||||
name:
|
||||
- gzip
|
||||
- tar
|
||||
state: present
|
||||
when: ansible_pkg_mgr == 'zypper'
|
||||
|
||||
- name: Install golang
|
||||
include: go.yaml
|
||||
|
||||
###########################################################################################################################
|
||||
# Install and config CGRateS
|
||||
- name: Install and config CGRateS
|
||||
include: cgrates.yaml
|
||||
|
||||
# Configure FreeSwitch
|
||||
- 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: Remove FreeSWITCH default config from /etc/freesitch
|
||||
become: yes
|
||||
shell: 'sudo rm -rf *'
|
||||
args:
|
||||
chdir: '/etc/freeswitch'
|
||||
|
||||
- name: Copy our custom config for FreeSWITCH in /etc/freesitch
|
||||
become: yes
|
||||
shell: 'sudo cp -r {{ cgrates_dir }}/data/tutorial_tests/fs_evsock/freeswitch/etc/freeswitch/* /etc/freeswitch'
|
||||
args:
|
||||
chdir: '/etc/freeswitch'
|
||||
|
||||
# Configure PJSUA
|
||||
- name: Config PJSUA
|
||||
include: pjsua.yaml
|
||||
28
data/ansible/calls/freeswitch/pjsua.yaml
Normal file
28
data/ansible/calls/freeswitch/pjsua.yaml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- name: Download PJSUA
|
||||
become: yes
|
||||
shell: 'sudo wget https://www.pjsip.org/release/2.9/pjproject-2.9.tar.bz2'
|
||||
args:
|
||||
chdir: '/tmp'
|
||||
|
||||
- name: Unzip PJSUA
|
||||
become: yes
|
||||
shell: 'sudo tar -xvf pjproject-2.9.tar.bz2'
|
||||
args:
|
||||
chdir: '/tmp'
|
||||
|
||||
- name: Export CFLAGS
|
||||
become: yes
|
||||
shell: 'export CFLAGS="$CFLAGS -fPIC"'
|
||||
|
||||
- name: Install PJSUA
|
||||
become: yes
|
||||
shell: 'sudo ./configure && make dep && make && make install'
|
||||
args:
|
||||
chdir: '/tmp/pjproject-2.9'
|
||||
|
||||
- name: Copy PJSUA into /usr/bin
|
||||
become: yes
|
||||
shell: 'sudo mv pjsua-x86_64-unknown-linux-gnu /usr/bin/pjsua'
|
||||
args:
|
||||
chdir: '/tmp/pjproject-2.9/pjsip-apps/bin'
|
||||
Reference in New Issue
Block a user