Use ansible roles for reusable tasks

This commit is contained in:
ionutboangiu
2023-05-04 12:30:25 -04:00
committed by Dan Christian Bogos
parent e17d952f9c
commit a2e3fa1d3a
19 changed files with 350 additions and 602 deletions

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,140 +1,19 @@
---
- hosts: local
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.18'
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
dependencies:
- build-essential
- git
- redis-server
- mariadb-server
- postgresql
- postgresql-contrib
- python-dev
- gcc
- make
- binutils
- libasound2-dev
- autoconf
- openssl
- libssl-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: '{{ user }}'
- name: Set up environment in order to run call tests for Asterisk
hosts: all
tasks:
###########################################################################################################################
# install dependencies
- name: Install dependencies
become: yes
apt: name={{ dependencies }} state=present
- name: Install Go
import_role:
name: ../../roles/install_go
###########################################################################################################################
# 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 Asterisk
become: yes
shell: "sudo wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-18-current.tar.gz"
args:
chdir: '/tmp'
- name: Unzip Asterisk
become: yes
shell: "sudo tar xzvf asterisk-18-current.tar.gz"
args:
chdir: '/tmp'
- name: Install and configure CGRateS
import_role:
name: ../../roles/install_cgrates
- name: Configure Asterisk
become: yes
shell: "sudo ./configure --with-jansson-bundled"
args:
chdir: '/tmp/asterisk-18.5.0'
import_role:
name: ../../roles/install_asterisk
- name: Make Asterisk
become: yes
shell: "sudo make"
args:
chdir: '/tmp/asterisk-18.5.0'
- name: Make all Asterisk
become: yes
shell: "make all"
args:
chdir: '/tmp/asterisk-18.5.0'
- name: Make install Asterisk
become: yes
shell: "sudo make install"
args:
chdir: '/tmp/asterisk-18.5.0'
- name: Make samples Asterisk
become: yes
shell: "sudo make samples"
args:
chdir: '/tmp/asterisk-18.5.0'
- name: Make config Asterisk
become: yes
shell: "sudo make config"
args:
chdir: '/tmp/asterisk-18.5.0'
- name: Add user for Asterisk
become: yes
shell: 'sudo adduser --quiet --system --group --disabled-password --shell /bin/false --gecos "Asterisk" asterisk || true'
- name: Add user for CGRateS
become: yes
shell: 'sudo useradd cgrates'
# Configure PJSUA
- name: Config PJSUA
include: pjsua.yaml
- name: Configure 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

@@ -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,105 +1,18 @@
---
- name: Install Python
- name: Set up environment in order to run call tests for Freeswitch
hosts: all
remote_user: '{{ user }}'
gather_facts: false
tasks:
- name: Install Python3s
raw: apt -y install python3
become: true
- name: Install freeswitch
import_role:
name: ../../roles/install_freeswitch
- name: Install Go
import_role:
name: ../../roles/install_go
- 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.18'
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
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: '{{ user }}'
tasks:
###########################################################################################################################
# install dependencies
- name: Install dependencies
become: yes
apt: name={{ dependencies }} state=present
- name: apt-get update && apt-get install gnupg2
become: yes
shell: 'apt-get update && apt-get install -y gnupg2 wget lsb-release'
- name: Freeswitch add key
become: yes
shell: 'wget -O /usr/share/keyrings/freeswitch-archive-keyring.gpg https://files.freeswitch.org/repo/deb/debian-release/freeswitch-archive-keyring.gpg'
- name: Add FreeSwitch apt repository
become: yes
shell: 'echo "deb [signed-by=/usr/share/keyrings/freeswitch-archive-keyring.gpg trusted=yes] http://files.freeswitch.org/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list'
- name: Add FreeSwitch apt repository 1.8
become: yes
shell: 'echo "deb-src [signed-by=/usr/share/keyrings/freeswitch-archive-keyring.gpg trusted=yes] http://files.freeswitch.org/repo/deb/debian-unstable/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list'
- name: Install FreeSwitch
become: yes
shell: 'apt-get update && apt-get install -y freeswitch-meta-all'
###########################################################################################################################
# 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
import_role:
name: ../../roles/install_cgrates
# Configure FreeSwitch
- name: Unzip FreeSWITCH config
become: yes
shell: 'sudo tar -xvf freeswitch_conf.tar.gz'
@@ -112,6 +25,12 @@
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 *'
@@ -124,10 +43,6 @@
args:
chdir: '/etc/freeswitch'
- name: Add user for CGRateS
become: yes
shell: 'sudo useradd cgrates'
# Configure PJSUA
- name: Config PJSUA
include: pjsua.yaml
- name: Configure PJSUA
import_role:
name: ../../roles/install_pjsua

View File

@@ -0,0 +1,21 @@
---
asterisk_version: "20-current"
asterisk_major_version: "{{ asterisk_version.split('-')[0] }}"
asterisk_download_url: "https://downloads.asterisk.org/pub/telephony/asterisk"
asterisk_archive_dest: "/tmp"
asterisk_src_dir: "/usr/src"
asterisk_dependencies:
- build-essential
- libasound2-dev
- autoconf
- openssl
- libssl-dev
- libxml2-dev
- libncurses5-dev
- uuid-dev
- sqlite3
- libsqlite3-dev
- pkg-config
- libedit-dev
- libjansson-dev

View File

@@ -0,0 +1,47 @@
---
- name: Install Asterisk dependencies
become: yes
apt:
name: "{{ item }}"
state: present
update_cache: "{{ 'yes' if item == asterisk_dependencies[0] else 'no' }}"
cache_valid_time: 86400
with_items: "{{ asterisk_dependencies }}"
- name: Download Asterisk
get_url:
url: "{{ asterisk_download_url }}/asterisk-{{ asterisk_version }}.tar.gz"
dest: "{{ asterisk_archive_dest }}/asterisk-{{ asterisk_version }}.tar.gz"
- name: Extract Asterisk
become: yes
unarchive:
src: "{{ asterisk_archive_dest }}/asterisk-{{ asterisk_version }}.tar.gz"
dest: "{{ asterisk_src_dir }}"
remote_src: yes
- name: Find extracted Asterisk directory
command: "find {{ asterisk_src_dir }} -type d -name 'asterisk-{{ asterisk_major_version }}*'"
register: asterisk_dir
- name: Install Asterisk
become: yes
shell: "{{ item }}"
args:
chdir: "{{ asterisk_dir.stdout }}"
loop:
- "./configure --with-jansson-bundled"
- "make menuselect.makeopts"
- "make"
- "make install"
- "make samples"
- "make config"
- "ldconfig"
- name: Create Asterisk user
become: yes
user:
name: asterisk
system: yes
createhome: no
shell: /bin/false

View File

@@ -0,0 +1,15 @@
---
golang_gopath: "/home/{{ ansible_user }}/go"
cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates"
golang_install_dir: /usr/local/go
git_version: "master"
# CGRateS dependencies
cgrates_dependencies:
- git
- redis-server
- mariadb-server
- postgresql
- postgresql-contrib
- make
- gcc

View File

@@ -0,0 +1,61 @@
---
- name: Install CGRateS dependencies
become: yes
ansible.builtin.package:
name: '{{ item }}'
state: present
update_cache: "{{ 'yes' if item == cgrates_dependencies[0] else 'no' }}"
cache_valid_time: 86400
with_items: "{{ cgrates_dependencies }}"
- name: Create cgrates directory
ansible.builtin.file:
state: directory
mode: 'u=rwx,go=rx'
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
dest: '{{ cgrates_dir }}'
- name: Git clone cgrates
ansible.builtin.git:
repo: https://github.com/cgrates/cgrates.git
dest: '{{ cgrates_dir }}'
update: yes
force: yes
version: '{{ git_version }}'
- name: Build cgrates
ansible.builtin.command:
cmd: bash -lc "source /etc/profile.d/golang.sh && sh {{ cgrates_dir }}/build.sh"
args:
chdir: '{{ cgrates_dir }}'
become_user: '{{ ansible_user }}'
- name: Create symbolic links
ansible.builtin.file:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
state: link
become: yes
loop:
- { src: "{{ cgrates_dir }}/data", dest: "/usr/share/cgrates" }
- { src: "{{ golang_gopath }}/bin/cgr-engine", dest: "/usr/bin/cgr-engine" }
- name: Run post install scripts
ansible.builtin.shell:
cmd: "{{ item.cmd }}"
chdir: '{{ cgrates_dir }}/data/storage/{{ item.db }}'
become: yes
loop:
- { db: "mysql", cmd: "sh setup_ers_db.sh root CGRateS.org localhost" }
- { db: "mysql", cmd: "sh setup_cgr_db.sh root CGRateS.org localhost" }
- { db: "postgres", cmd: "sh create_db_with_users.sh" }
- { db: "postgres", cmd: "sh create_ers_db.sh" }
- { db: "mongo", cmd: "sh setup_cgr_db.sh" }
- name: Set versions
ansible.builtin.shell:
cmd: '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

@@ -0,0 +1,6 @@
---
signalwire_token: YOURSIGNALWIRETOKEN
freeswitch_dependencies:
- gnupg2
- wget
- lsb-release

View File

@@ -0,0 +1,38 @@
---
- name: Update apt cache and install required packages
become: yes
ansible.builtin.apt:
name: "{{ item }}"
state: present
update_cache: "{{ 'yes' if item == freeswitch_dependencies[0] else 'no' }}"
with_items: "{{ freeswitch_dependencies }}"
- name: Download SignalWire FreeSWITCH GPG key
become: yes
ansible.builtin.get_url:
url: https://freeswitch.signalwire.com/repo/deb/debian-release/signalwire-freeswitch-repo.gpg
dest: /usr/share/keyrings/signalwire-freeswitch-repo.gpg
headers:
Authorization: "Basic {{ ('signalwire:' ~ signalwire_token) | b64encode }}"
- name: Create auth.conf file
become: yes
ansible.builtin.copy:
dest: /etc/apt/auth.conf
content: |
machine freeswitch.signalwire.com login signalwire password {{ signalwire_token }}
mode: '0600'
- name: Add SignalWire FreeSWITCH repository
become: yes
ansible.builtin.template:
src: freeswitch.list.j2
dest: /etc/apt/sources.list.d/freeswitch.list
- name: Update apt cache and install FreeSWITCH
become: yes
ansible.builtin.apt:
name: freeswitch-meta-all
state: present
update_cache: yes

View File

@@ -0,0 +1,2 @@
deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ {{ ansible_distribution_release }} main
deb-src [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ {{ ansible_distribution_release }} main

View File

@@ -0,0 +1,28 @@
---
# defaults for install_go
# Go version to install
golang_version: 1.20.4
# Expected go version output
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Set the Go workspace directory
golang_gopath: /home/{{ ansible_user }}/go
# Set the directory to download the Go archive to
golang_download_dir: /tmp
# Set the mirror to download Go from
golang_mirror: https://storage.googleapis.com/golang
# Set the filename of the Go archive to download
golang_redis_filename: go{{ golang_version }}.linux-amd64.tar.gz
# Set the Go installation directory
golang_install_dir: /usr/local/go
# Go dependencies
go_dependencies:
- curl
- tar

View File

@@ -0,0 +1,49 @@
---
- name: Check if Go is already installed
command: /usr/local/go/bin/go version
ignore_errors: true
register: go_version_output
- name: Install Go dependencies
become: yes
apt:
name: '{{ item }}'
state: present
update_cache: "{{ 'yes' if item == go_dependencies[0] else 'no' }}"
cache_valid_time: 86400
with_items: "{{ go_dependencies }}"
- name: Remove old installation of Go if needed
become: yes
file:
path: /usr/local/go
state: absent
when: go_version_output.rc == 0 and go_version_output.stdout != go_version_target
- name: Create Go language SDK installation directory
become: yes
file:
path: '{{ golang_install_dir }}'
state: directory
mode: '0755'
- name: Download Go language SDK
get_url:
url: '{{ golang_mirror }}/{{ golang_redis_filename }}'
dest: '{{ golang_download_dir }}/{{ golang_redis_filename }}'
mode: '0644'
- name: Install Go language SDK
become: yes
unarchive:
src: '{{ golang_download_dir }}/{{ golang_redis_filename }}'
remote_src: true
dest: '{{ golang_install_dir | dirname }}'
creates: '{{ golang_install_dir }}/bin'
- name: Set Go language SDK environment variables
become: yes
template:
src: golang.sh.j2
dest: /etc/profile.d/golang.sh
mode: '0644'

View File

@@ -1,12 +1,11 @@
#!/bin/sh
{{ ansible_managed | comment('plain') }}
{# Comment that describes the purpose of the template #}
export GOROOT='{{ golang_install_dir }}'
export PATH=$PATH:$GOROOT/bin
{% if golang_gopath not in (None, '') %}
{% if golang_gopath %}
export GOPATH="{{ golang_gopath }}"
export PATH=$PATH:$GOPATH/bin
{% endif %}
{% endif %}

View File

@@ -0,0 +1,10 @@
---
pjsua_version: "2.9"
pjsua_url: "https://github.com/pjsip/pjproject/archive/refs/tags/{{ pjsua_version }}.tar.gz"
tmp_dir: "/tmp"
# PJSUA dependencies
pjsua_dependencies:
- libasound2-dev
- libssl-dev
- build-essential

View File

@@ -0,0 +1,39 @@
---
- name: Install PJSUA dependencies
become: yes
ansible.builtin.package:
name: '{{ item }}'
state: present
update_cache: "{{ 'yes' if item == pjsua_dependencies[0] else 'no' }}"
cache_valid_time: 86400
with_items: "{{ pjsua_dependencies }}"
- name: Download PJSUA
ansible.builtin.get_url:
url: "{{ pjsua_url }}"
dest: "{{ tmp_dir }}/{{ pjsua_version }}.tar.gz"
- name: Unzip PJSUA
become: yes
ansible.builtin.unarchive:
src: "{{ tmp_dir }}/{{ pjsua_version }}.tar.gz"
dest: "{{ tmp_dir }}"
remote_src: yes
- name: Install PJSUA
become: yes
ansible.builtin.shell:
cmd: './configure CFLAGS="$CFLAGS -fPIC" && make dep && make && make install'
chdir: '{{ tmp_dir }}/pjproject-{{ pjsua_version }}'
- name: Copy PJSUA into /usr/bin
become: yes
ansible.builtin.command:
cmd: 'cp pjsua-x86_64-unknown-linux-gnu /usr/bin/pjsua'
chdir: '{{ tmp_dir }}/pjproject-{{ pjsua_version }}/pjsip-apps/bin'
- name: Cleanup temporary PJSUA files
become: yes
ansible.builtin.file:
path: '{{ tmp_dir }}/pjproject-{{ pjsua_version }}'
state: absent