From ca0b9870b716d4b1ab1bdb19682d18961b3e446a Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Wed, 1 May 2024 16:56:24 +0300 Subject: [PATCH] Add playbook for osips+diam setup - installs go - sets up cgrates - installs nightly version of opensips and modules - uses the prepaid opensips.cfg from tutorials by default - installs and sets up freediameter - installs pjsua and helper scripts --- data/ansible/osips_diameter/hosts | 5 ++ data/ansible/osips_diameter/main.yaml | 64 +++++++++++++++++++ .../osips_diam/etc/opensips/opensips_acc.cfg | 2 +- .../etc/opensips/opensips_ccr_postpaid.cfg | 4 +- .../etc/opensips/opensips_ccr_prepaid.cfg | 6 +- 5 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 data/ansible/osips_diameter/hosts create mode 100644 data/ansible/osips_diameter/main.yaml diff --git a/data/ansible/osips_diameter/hosts b/data/ansible/osips_diameter/hosts new file mode 100644 index 000000000..258fe441b --- /dev/null +++ b/data/ansible/osips_diameter/hosts @@ -0,0 +1,5 @@ +# Ansible Inventory File + +[all] +example_host ansible_host=192.168.122.42 ansible_port=50026 ansible_user=example_user user=example_user + diff --git a/data/ansible/osips_diameter/main.yaml b/data/ansible/osips_diameter/main.yaml new file mode 100644 index 000000000..567f6cae0 --- /dev/null +++ b/data/ansible/osips_diameter/main.yaml @@ -0,0 +1,64 @@ +--- +- hosts: all + roles: + - ../roles/go + - role: ../roles/cgrates + vars: + cgrates_dbs: + - mysql + cgrates_dependencies: + - git + - redis-server + - mariadb-server + - xxd # needed for unix2ntp script (added here for convenience) + + - role: ../roles/opensips + vars: + opensips_cfg_path: /usr/share/cgrates/tutorials/osips_diam/etc/opensips/opensips_ccr_prepaid.cfg + opensips_dict_path: /usr/share/cgrates/tutorials/osips_diam/etc/opensips/dictionary.opensips + opensips_version: '3.5' + opensips_release_type: nightly + opensips_modules: + - opensips-auth-modules + - opensips-diameter-module + - opensips-json-module + - opensips-mysql-module + opensips_cfg_replacements: + - before: '^socket=udp:enp0s3:5060.*$' + after: 'socket=udp:{{ ansible_default_ipv4.interface }}:5060' + + - role: ../roles/freediameter + vars: + fd_dns_entries: + - ip: '{{ ansible_default_ipv4.address }}' + hostname: '{{ fd_client_identity }}' + - ip: '{{ ansible_default_ipv4.address }}' + hostname: '{{ fd_server_identity }}' + + - role: ../roles/pjsua + vars: + pjsua_helper_scripts: true + + post_tasks: + - name: Configure diameter listen address in CGRateS cfg + become: true + ansible.builtin.lineinfile: + path: /usr/share/cgrates/tutorials/osips_diam/etc/cgrates/cgrates.json + regexp: '^\s*"listen": "192\.168\.122\.42:3868",\s*$' + line: '"listen": "{{ ansible_default_ipv4.address }}:3868",' + + - name: Ensure opensips is allowed to access privkey.pem + become: true + ansible.builtin.file: + path: /etc/freeDiameter/tls/privkey.pem + mode: 0644 + + - name: Move unix2ntp script to /usr/local/bin + become: true + ansible.builtin.copy: + src: /usr/share/cgrates/tutorials/osips_diam/etc/opensips/unix2ntp + dest: /usr/local/bin + owner: root + group: root + remote_src: yes + mode: 0755 \ No newline at end of file diff --git a/data/tutorials/osips_diam/etc/opensips/opensips_acc.cfg b/data/tutorials/osips_diam/etc/opensips/opensips_acc.cfg index 1da12b68d..4b39b63e4 100644 --- a/data/tutorials/osips_diam/etc/opensips/opensips_acc.cfg +++ b/data/tutorials/osips_diam/etc/opensips/opensips_acc.cfg @@ -58,7 +58,7 @@ loadmodule "sipmsgops.so" #### FIFO Management Interface loadmodule "mi_fifo.so" -modparam("mi_fifo", "fifo_name", "/run/opensips/opensips_fifo") +modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") modparam("mi_fifo", "fifo_mode", 0666) #### USeR LOCation module diff --git a/data/tutorials/osips_diam/etc/opensips/opensips_ccr_postpaid.cfg b/data/tutorials/osips_diam/etc/opensips/opensips_ccr_postpaid.cfg index 5064cbc1c..d4f783ff3 100644 --- a/data/tutorials/osips_diam/etc/opensips/opensips_ccr_postpaid.cfg +++ b/data/tutorials/osips_diam/etc/opensips/opensips_ccr_postpaid.cfg @@ -58,7 +58,7 @@ loadmodule "sipmsgops.so" #### FIFO Management Interface loadmodule "mi_fifo.so" -modparam("mi_fifo", "fifo_name", "/run/opensips/opensips_fifo") +modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") modparam("mi_fifo", "fifo_mode", 0666) #### USeR LOCation module @@ -224,7 +224,7 @@ route[handle_answer] { route[handle_hangup] { $var(duration) = $Ts - $dlg_val(answertime); - exec("/usr/share/cgrates/tutorials/osips_diam/etc/opensips/unix2ntp", "$dlg_val(answertime)", $var(answertime32bit), , ); + exec("/usr/local/bin/unix2ntp", "$dlg_val(answertime)", $var(answertime32bit), , ); $var(payload) = "[ { \"Session-Id\": \"" + $dlg_val(callid) + "\" }, { \"Origin-Host\": \"client.diameter.test\" }, diff --git a/data/tutorials/osips_diam/etc/opensips/opensips_ccr_prepaid.cfg b/data/tutorials/osips_diam/etc/opensips/opensips_ccr_prepaid.cfg index a53ca3d74..31198f01b 100644 --- a/data/tutorials/osips_diam/etc/opensips/opensips_ccr_prepaid.cfg +++ b/data/tutorials/osips_diam/etc/opensips/opensips_ccr_prepaid.cfg @@ -58,7 +58,7 @@ loadmodule "sipmsgops.so" #### FIFO Management Interface loadmodule "mi_fifo.so" -modparam("mi_fifo", "fifo_name", "/run/opensips/opensips_fifo") +modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") modparam("mi_fifo", "fifo_mode", 0666) #### USeR LOCation module @@ -177,7 +177,7 @@ route{ # use the unix2ntp helper script to convert unix time to 32bit format # for the Event-Timestamp AVP # can this be done directly inside the cfg file? - exec("/usr/share/cgrates/tutorials/osips_diam/etc/opensips/unix2ntp", "$dlg_val(setuptime)", $var(setuptime32bit), , ); + exec("/usr/local/bin/unix2ntp", "$dlg_val(setuptime)", $var(setuptime32bit), , ); # Send blocking CCR INITIAL_REQUEST and retrieve MaxUsage $var(payload) = "[ @@ -272,7 +272,7 @@ route{ route[handle_answer] { $dlg_val(answertime) = $Ts; - exec("/usr/share/cgrates/tutorials/osips_diam/etc/opensips/unix2ntp", "$dlg_val(answertime)", $dlg_val(answertime32bit), , ); + exec("/usr/local/bin/unix2ntp", "$dlg_val(answertime)", $dlg_val(answertime32bit), , ); $var(payload) = "[ { \"Session-Id\": \"" + $dlg_val(callid) + "\" }, { \"Origin-Host\": \"client.diameter.test\" },