Skip to content

Commit

Permalink
Merge pull request #1405 from m-anish/pbx
Browse files Browse the repository at this point in the history
Asterisk (with chan_dongle) and FreePBX
  • Loading branch information
holta committed Feb 9, 2019
2 parents 72142db + b612937 commit 07081cd
Show file tree
Hide file tree
Showing 18 changed files with 580 additions and 1 deletion.
6 changes: 6 additions & 0 deletions roles/6-generic-apps/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
# when: owncloud_install
# tags: owncloud

- name: PBX
include_role:
name: pbx
when: pbx_install
tags: pbx

- name: WORDPRESS
include_role:
name: wordpress
Expand Down
2 changes: 1 addition & 1 deletion roles/network/tasks/hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
lineinfile:
path: /etc/hosts
regexp: '^172\.18\.96\.1'
line: '172.18.96.1 {{ iiab_hostname }}.{{ iiab_domain }} {{ iiab_hostname }} box box.lan'
line: '172.18.96.1 {{ iiab_hostname }}.{{ iiab_domain }} {{ iiab_hostname }} box box.lan pbx pbx.lan'
state: present
when: iiab_lan_iface != "none" and not installing

Expand Down
32 changes: 32 additions & 0 deletions roles/pbx/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
==========
PBX README
==========

This 'pbx' playbook adds `Asterisk <https://asterisk.org/>`_ and `FreePBX <https://freepbx.org/>`_ to Internet-in-a-Box (IIAB) for VoIP and SIP functionality.

Asterisk is a software implementation of a private branch exchange (PBX). In conjunction with suitable telephony hardware interfaces and network applications, Asterisk is used to establish and control telephone calls between telecommunication endpoints, such as customary telephone sets, destinations on the public switched telephone network (PSTN), and devices or services on Voice over Internet Protocol (VoIP) networks. Its name comes from the asterisk (*) symbol for a signal used in dual-tone multi-frequency (DTMF) dialing.

FreePBX is a web-based open source GUI (graphical user interface) that controls and manages Asterisk (PBX), an open source communication server.

Using It
--------

Prior to installing IIAB, make sure your `/etc/iiab/local_vars.yml <http://wiki.laptop.org/go/IIAB/FAQ#What_is_local_vars.yml_and_how_do_I_customize_it.3F>`_ contains::

pbx_install: True
pbx_enabled: True

Optionally, you may want to enable `chan_dongle <https://github.com/wdoekes/asterisk-chan-dongle>`_, which is a channel driver for Huawei UMTS cards allowing regular voice calls over GSM. You will need to configure a dongle post-install, for it to be recognized properly::

asterisk_chan_dongle: True

After installing PBX as part of IIAB, please visit http://pbx.lan/freepbx and proceed with initial configuration — which asks you to create a login/password.

You can monitor the PBX service with command::

systemctl status freepbx

Attribution
-----------

This 'pbx' playbook was heavily inspired by Yannik Sembritzki's `Asterisk <https://github.com/Yannik/ansible-role-asterisk>`_ and `FreePBX <https://github.com/Yannik/ansible-role-freepbx>`_ Ansible work.
27 changes: 27 additions & 0 deletions roles/pbx/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# pbx_install: False
# pbx_enabled: False
# asterisk_chan_dongle: False

# All above are set in: github.com/iiab/iiab/blob/master/vars/default_vars.yml
# If nec, change them by editing /etc/iiab/local_vars.yml prior to installing!

pbx_installed: False

asterisk_url: http://downloads.asterisk.org/pub/telephony/asterisk/
asterisk_src_file: asterisk-16-current.tar.gz
asterisk_src_dir: /opt/iiab/asterisk

freepbx_url: http://mirror.freepbx.org/modules/packages/freepbx/
freepbx_src_file: freepbx-15.0-latest.tgz
freepbx_src_dir: /opt/iiab/freepbx
freepbx_install_dir: /var/www/html/freepbx

asterisk_db_host: localhost
asterisk_db_user: asterisk
asterisk_db_dbname: asterisk
asterisk_db_password: asterisk
asterisk_db_cdrdbname: asteriskcdrdb

chan_dongle_url: https://github.com/wdoekes/asterisk-chan-dongle/archive/
chan_dongle_src_file: master.zip
chan_dongle_src_dir: /opt/iiab/chan_dongle
3 changes: 3 additions & 0 deletions roles/pbx/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- { role: nodejs, tags: ['nodejs'], when: pbx_install and (nodejs_version == "10.x")}

151 changes: 151 additions & 0 deletions roles/pbx/tasks/asterisk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
- name: Asterisk - Install dependencies
include: asterisk_dependencies.yml

- name: Asterisk - Download software to /opt/iiab/downloads
get_url:
url: "{{ asterisk_url }}/{{ asterisk_src_file }}"
dest: "{{ downloads_dir }}/{{ asterisk_src_file }}"
timeout: "{{ download_timeout }}"
when: internet_available

- name: Asterisk - Check for /opt/iiab/downloads/{{ asterisk_src_file }}
stat:
path: "{{ downloads_dir }}/{{ asterisk_src_file }}"
register: asterisk_src

- name: Asterisk - FAIL (force Ansible to exit) IF /opt/iiab/downloads/{{ asterisk_src_file }} doesn't exist
fail:
msg: "{ downloads_dir }}/{{ asterisk_src_file }} is REQUIRED in order to install."
when: not asterisk_src.stat.exists

- name: Asterisk - Create install source directory
file:
path: "{{ asterisk_src_dir }}"
state: directory

- name: Asterisk - Extract source
unarchive:
src: "{{ downloads_dir }}/{{ asterisk_src_file }}"
dest: "{{ asterisk_src_dir }}"
owner: root
group: root
extra_opts: [--strip-components=1]
creates: "{{ asterisk_src_dir }}/Makefile"

- name: Asterisk - Download mp3 decoder library into source tree
command: "./contrib/scripts/get_mp3_source.sh"
args:
chdir: "{{ asterisk_src_dir }}"
creates: "addons/mp3/mpg123.h"

- name: Asterisk - Install aptitude (otherwise install_prereq fails?)
package:
name: aptitude
state: latest

- name: Asterisk - Ensure all dependencies are resolved - CAN TAKE 2 MIN OR LONGER!
shell: export DEBIAN_FRONTEND=noninteractive && ./contrib/scripts/install_prereq install
args:
chdir: "{{ asterisk_src_dir }}"

- name: Asterisk - Run the configure script
command: "./configure --with-jansson-bundled"
args:
chdir: "{{ asterisk_src_dir }}"

- name: Asterisk - Run make menuselect.makeopts
command: "make menuselect.makeopts"
args:
chdir: "{{ asterisk_src_dir }}"
creates: "menuselect.makeopts"

- name: Asterisk - Do a bit of menuselect configuration
command: >
menuselect/menuselect --enable app_macro --enable format_mp3
--enable CORE-SOUNDS-EN-WAV --enable CORE-SOUNDS-EN-G722
--enable EXTRA-SOUNDS-EN-WAV --enable EXTRA-SOUNDS-EN-G722 --enable EXTRA-SOUNDS-EN-GSM
--disable-category MENUSELECT_MOH
args:
chdir: "{{ asterisk_src_dir }}"

- name: Asterisk - Run 'make' - CAN TAKE 10 MIN OR LONGER!
command: make
args:
chdir: "{{ asterisk_src_dir }}"
creates: "defaults.h"

- name: Asterisk - Run 'make install' - CAN TAKE 3 MIN OR LONGER!
command: make install
args:
chdir: "{{ asterisk_src_dir }}"
creates: "/usr/sbin/asterisk"

- name: Asterisk - Run 'make config'
command: make config
args:
chdir: "{{ asterisk_src_dir }}"

- name: Asterisk - Run 'make samples'
command: make samples
args:
chdir: "{{ asterisk_src_dir }}"

- name: Asterisk - Run 'ldconfig'
shell: ldconfig
args:
chdir: "{{ asterisk_src_dir }}"

- name: Asterisk - Ensure group 'asterisk' exists
group:
name: asterisk
state: present

- name: Asterisk - Ensure user 'asterisk' exists, and belongs to the required groups
user:
name: asterisk
group: asterisk
groups: audio,dialout
home: "/var/lib/asterisk"
system: yes
append: yes

- name: 'Asterisk - Set ownership of 5 directories: /etc/asterisk, /var/lib/asterisk, /var/log/asterisk, /var/spool/asterisk, /usr/lib/asterisk'
file:
dest: "{{ item }}"
owner: asterisk
group: asterisk
recurse: yes
with_items:
- /etc/asterisk
- /var/lib/asterisk
- /var/log/asterisk
- /var/spool/asterisk
- /usr/lib/asterisk

- name: Asterisk - Set default user to 'asterisk' in /etc/default/asterisk
lineinfile:
path: /etc/default/asterisk
regexp: 'AST_USER='
line: 'AST_USER="asterisk"'

- name: Asterisk - Set default group to 'asterisk' in /etc/default/asterisk
lineinfile:
path: /etc/default/asterisk
regexp: 'AST_GROUP='
line: 'AST_GROUP="asterisk"'

- name: Asterisk - Set default user to 'asterisk' in /etc/asterisk/asterisk.conf
lineinfile:
path: /etc/asterisk/asterisk.conf
regexp: 'runuser ='
line: 'runuser = asterisk'

- name: Asterisk - Set default group to 'asterisk' in /etc/asterisk/asterisk.conf
lineinfile:
path: /etc/asterisk/asterisk.conf
regexp: 'rungroup ='
line: 'rungroup = asterisk'

- name: Asterisk - Install chan_dongle
include: chan_dongle.yml
when: asterisk_chan_dongle
16 changes: 16 additions & 0 deletions roles/pbx/tasks/asterisk_dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: Asterisk - Install dependencies
package:
name:
- git
- curl
- wget
- libnewt-dev
- libssl-dev
- libncurses5-dev
- subversion
- libsqlite3-dev
- build-essential
- libjansson-dev
- libxml2-dev
- uuid-dev
state: latest
68 changes: 68 additions & 0 deletions roles/pbx/tasks/chan_dongle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
- name: chan_dongle - Download software to /opt/iiab/downloads
get_url:
url: "{{ chan_dongle_url }}/{{ chan_dongle_src_file }}"
dest: "{{ downloads_dir }}/{{ chan_dongle_src_file }}"
timeout: "{{ download_timeout }}"
when: internet_available

- name: chan_dongle - Check for /opt/iiab/downloads/{{ chan_dongle_src_file }}
stat:
path: "{{ downloads_dir }}/{{ chan_dongle_src_file }}"
register: chan_dongle_src

- name: chan_dongle - FAIL (force Ansible to exit) IF /opt/iiab/downloads/{{ chan_dongle_src_file }} doesn't exist
fail:
msg: "{ downloads_dir }}/{{ chan_dongle_src_file }} is REQUIRED in order to install."
when: not chan_dongle_src.stat.exists

- name: chan_dongle - Create install source directory
file:
path: "{{ chan_dongle_src_dir }}"
state: directory

- name: chan_dongle - Extract source
unarchive:
src: "{{ downloads_dir }}/{{ chan_dongle_src_file }}"
dest: "{{ downloads_dir }}"
owner: root
group: root

- name: chan_dongle - move to {{ chan_dongle_src_dir }}
command: rsync -av {{ downloads_dir }}/asterisk-chan-dongle-master/ {{ chan_dongle_src_dir }}
args:
chdir: "{{ downloads_dir }}"

- name: chan_dongle - Run the bootstrap script
command: "./bootstrap"
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "{{ chan_dongle_src_dir }}/configure"

- name: chan_dongle - Find out asterisk version
shell: asterisk -V |cut -d " " -f 2
register: asterisk_ver

- name: chan_dongle - Run the configure script
command: "./configure --with-astversion={{asterisk_ver.stdout}}"
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "{{ chan_dongle_src_dir }}/Makefile"

- name: chan_dongle - Run 'make'
command: make
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "{{ chan_dongle_src_dir }}/chan_dongle.o"

- name: chan_dongle - Run 'make install'
command: make install
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "/usr/lib/asterisk/modules/chan_dongle.so"

- name: chan_dongle - Copy dongle.conf over
command: cp {{ chan_dongle_src_dir }}/etc/dongle.conf /etc/asterisk/
args:
chdir: "{{ chan_dongle_src_dir }}"
creates: "/etc/asterisk/dongle.conf"

0 comments on commit 07081cd

Please sign in to comment.