Add ansible script for install and configure CGRateS with Asterisk

This commit is contained in:
TeoV
2019-09-18 07:40:58 -04:00
committed by Dan Christian Bogos
parent c93282a165
commit 4134eb2b16
5 changed files with 342 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
---
- 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 }}"
- 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/'

View File

@@ -0,0 +1,122 @@
---
- 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: Register the current Go version (if any)
command: /usr/local/go/bin/go version
ignore_errors: yes
register: go_version
changed_when: false
- name: Remove old installation of Go
become: yes
file:
path: /usr/local/go
state: absent
when: go_version is failed or go_version.stdout != go_version_target
- 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:
dest: ~/.bashrc
line: export PATH=$PATH:$GOROOT/bin
insertafter: last
- name: Export GOPATH for root
become: yes
lineinfile:
dest: ~/.bashrc
line: export GOPATH='{{ golang_gopath }}'
insertafter: last
- name: Add GOPATH to PATH for root
become: yes
lineinfile:
dest: ~/.bashrc
line: export PATH=$PATH:$GOPATH/bin
insertafter: last
- name: Export GOROOT
lineinfile:
dest: ~/.bashrc
line: export GOROOT='{{ golang_install_dir }}'
insertafter: last
- name: Add GOROOT to PATH
lineinfile:
dest: ~/.bashrc
line: export PATH=$PATH:$GOROOT/bin
insertafter: last
- name: Export GOPATH
lineinfile:
dest: ~/.bashrc
line: export GOPATH='{{ golang_gopath }}'
insertafter: last
- name: Add GOPATH to PATH
lineinfile:
dest: ~/.bashrc
line: export PATH=$PATH:$GOPATH/bin
insertafter: last

View 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 %}

View File

@@ -0,0 +1,128 @@
---
- hosts: all
vars:
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.13'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# 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
dependencies:
- build-essential
- git
- redis-server
- mariadb-server
- postgresql
- postgresql-contrib
- python-dev
- gcc
- make
- binutils
- libasound2-dev
- autoconf
- openssl
- libssl-dev
- libsrtp-dev
- libxml2-dev
- libncurses5-dev
- uuid-dev
- sqlite3
- libsqlite3-dev
- pkg-config
- libedit-dev
customPath: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
remote_user: '{{ gouser }}'
tasks:
###########################################################################################################################
# install dependencies
- name: Install dependencies
become: yes
apt: name={{ dependencies }} state=present
###########################################################################################################################
# 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 Asterisk
- name: Download files for asterisk
become: yes
shell: "sudo wget --no-check-certificate https://raw.githubusercontent.com/asterisk/third-party/master/pjproject/2.7.2/pjproject-2.7.2.tar.bz2"
args:
chdir: '/tmp'
- name: Download files for asterisk
become: yes
shell: "sudo wget --no-check-certificate https://raw.githubusercontent.com/asterisk/third-party/master/jansson/2.11/jansson-2.11.tar.bz2"
args:
chdir: '/tmp'
- name: Download Asterisk
become: yes
shell: "sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz"
args:
chdir: '/tmp'
- name: Unzip Asterisk
become: yes
shell: "sudo tar xzvf asterisk-16-current.tar.gz"
args:
chdir: '/tmp'
- name: Configure Asterisk
become: yes
shell: "sudo ./configure --with-jansson-bundled"
args:
chdir: '/tmp/asterisk-16.5.1'
- name: Make Asterisk
become: yes
shell: "sudo make"
args:
chdir: '/tmp/asterisk-16.5.1'
- name: Make install Asterisk
become: yes
shell: "sudo make install"
args:
chdir: '/tmp/asterisk-16.5.1'
- name: Add user for Asterisk
become: yes
shell: 'sudo adduser --quiet --system --group --disabled-password --shell /bin/false --gecos "Asterisk" asterisk || true'
# Configure PJSUA
- name: Config PJSUA
include: pjsua.yaml

View 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'