Add ansible role for kamailio

This commit is contained in:
ionutboangiu
2023-05-05 12:32:45 -04:00
committed by Dan Christian Bogos
parent d22df1736b
commit 4bc85329c5
13 changed files with 62 additions and 337 deletions

View File

@@ -10,10 +10,10 @@
import_role:
name: ../../roles/install_cgrates
- name: Configure Asterisk
- name: Install Asterisk
import_role:
name: ../../roles/install_asterisk
- name: Configure PJSUA
- name: Install PJSUA
import_role:
name: ../../roles/install_pjsua

View File

@@ -1,76 +0,0 @@
---
- name: create cgrates directory
become: yes
file:
state: directory
mode: 'u=rwx,go=rx'
owner: "{{ user }}"
group: "{{ user }}"
dest: '{{ cgrates_dir }}'
become_user: "{{ user }}"
- name: git clone cgrates
git:
repo: https://github.com/cgrates/cgrates.git
dest: '{{ cgrates_dir }}'
update: yes
force: yes
become: yes
become_user: "{{ user }}"
- 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 2
become: yes
file:
src: "{{ golang_gopath }}/bin/cgr-engine"
dest: "/usr/bin/cgr-engine"
state: link
# post install
- name: post install for ers mysql
become: yes
command: 'sh {{ cgrates_dir }}/data/storage/mysql/setup_ers_db.sh root CGRateS.org localhost'
args:
chdir: '{{ cgrates_dir }}/data/storage/mysql/'
- 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/'
- name: post install for ers postgres
become: yes
command: 'sh {{ cgrates_dir }}/data/storage/postgres/create_ers_db.sh'
args:
chdir: '{{ cgrates_dir }}/data/storage/postgres/'
- name: post install mongo
become: yes
command: 'sh {{ cgrates_dir }}/data/storage/mongo/setup_cgr_db.sh'
args:
chdir: '{{ cgrates_dir }}/data/storage/mongo/'
- name: set versions
command: 'cgr-migrator -exec=*set_versions -config_path=/usr/share/cgrates/conf/samples/tutmysql'
environment:
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"

View File

@@ -1,122 +0,0 @@
---
- 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

@@ -1,12 +0,0 @@
#!/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

@@ -1,87 +1,18 @@
---
- hosts: all
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.17.5'
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/{{ user }}/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
kamailio_package:
- kamailio
- kamailio-extra-modules
- kamailio-json-modules
dependencies:
- build-essential
- git
- wget
- 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: '{{ user }}'
tasks:
###########################################################################################################################
# install dependencies
- name: Install dependencies
become: yes
apt: name={{ dependencies }} state=present
# Install Kamailio
- name: Install Kamailio
become: yes
apt: name={{ kamailio_package }} state=latest
import_role:
name: ../../roles/install_kamailio
###########################################################################################################################
# Install Golang
- name: install unarchive dependencies (zypper)
become: yes
zypper:
name:
- gzip
- tar
state: present
when: ansible_pkg_mgr == 'zypper'
- name: Install Go
import_role:
name: ../../roles/install_go
- name: Install golang
include: go.yaml
- name: Install and configure CGRateS
import_role:
name: ../../roles/install_cgrates
###########################################################################################################################
# Install and config CGRateS
- name: Install and config CGRateS
include: cgrates.yaml
- name: Add user for CGRateS
become: yes
shell: 'sudo useradd cgrates'
# Configure PJSUA
- name: Config PJSUA
include: pjsua.yaml
- name: Install PJSUA
import_role:
name: ../../roles/install_pjsua

View File

@@ -1,29 +0,0 @@
---
- name: Download PJSUA
become: yes
shell: 'sudo wget https://github.com/pjsip/pjproject/archive/refs/tags/2.9.tar.gz'
args:
chdir: '/tmp'
- name: Unzip PJSUA
become: yes
shell: 'sudo tar -xvf 2.9.tar.gz'
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'

View File

@@ -2,12 +2,11 @@
- name: Install Asterisk dependencies
become: yes
apt:
name: "{{ item }}"
name: "{{ asterisk_dependencies }}"
state: present
update_cache: "{{ 'yes' if item == asterisk_dependencies[0] else 'no' }}"
update_cache: yes
cache_valid_time: 86400
with_items: "{{ asterisk_dependencies }}"
- name: Download Asterisk
get_url:
url: "{{ asterisk_download_url }}/asterisk-{{ asterisk_version }}.tar.gz"

View File

@@ -2,11 +2,10 @@
- name: Install CGRateS dependencies
become: yes
ansible.builtin.package:
name: '{{ item }}'
name: '{{ cgrates_dependencies }}'
state: present
update_cache: "{{ 'yes' if item == cgrates_dependencies[0] else 'no' }}"
update_cache: yes
cache_valid_time: 86400
with_items: "{{ cgrates_dependencies }}"
- name: Create cgrates directory
ansible.builtin.file:

View File

@@ -2,10 +2,10 @@
- name: Update apt cache and install required packages
become: yes
ansible.builtin.apt:
name: "{{ item }}"
name: "{{ freeswitch_dependencies }}"
state: present
update_cache: "{{ 'yes' if item == freeswitch_dependencies[0] else 'no' }}"
with_items: "{{ freeswitch_dependencies }}"
update_cache: yes
cache_valid_time: 86400
- name: Download SignalWire FreeSWITCH GPG key
become: yes

View File

@@ -7,11 +7,10 @@
- name: Install Go dependencies
become: yes
apt:
name: '{{ item }}'
name: '{{ go_dependencies }}'
state: present
update_cache: "{{ 'yes' if item == go_dependencies[0] else 'no' }}"
update_cache: yes
cache_valid_time: 86400
with_items: "{{ go_dependencies }}"
- name: Remove old installation of Go if needed
become: yes

View File

@@ -0,0 +1,9 @@
---
kamailio_repository_line: "deb http://deb.kamailio.org/kamailio{{ kamailio_version }} {{ ansible_distribution_release }} main"
kamailio_repository_src_line: "deb-src http://deb.kamailio.org/kamailio{{ kamailio_version }} {{ ansible_distribution_release }} main"
kamailio_repository_key_url: "http://deb.kamailio.org/kamailiodebkey.gpg"
kamailio_version: "56"
kamailio_packages:
- kamailio
- kamailio-extra-modules
- kamailio-json-modules

View File

@@ -0,0 +1,28 @@
---
- name: Add Kamailio repository key
become: yes
apt_key:
url: "{{ kamailio_repository_key_url }}"
state: present
- name: Add Kamailio repository
become: yes
apt_repository:
repo: "{{ kamailio_repository_line }}"
state: present
filename: kamailio
- name: Add Kamailio repository src
become: yes
apt_repository:
repo: "{{ kamailio_repository_src_line }}"
state: present
filename: kamailio
- name: Install Kamailio packages
become: yes
apt:
name: "{{ kamailio_packages }}"
state: latest
update_cache: yes
cache_valid_time: 86400

View File

@@ -2,11 +2,10 @@
- name: Install PJSUA dependencies
become: yes
ansible.builtin.package:
name: '{{ item }}'
name: '{{ pjsua_dependencies }}'
state: present
update_cache: "{{ 'yes' if item == pjsua_dependencies[0] else 'no' }}"
update_cache: yes
cache_valid_time: 86400
with_items: "{{ pjsua_dependencies }}"
- name: Download PJSUA
ansible.builtin.get_url: