Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asterisk (with chan_dongle) and FreePBX #1405

Merged
merged 81 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
f6089d9
Initial stab at adding a PBX. Playbooks and necessary config for Aste…
m-anish Jan 17, 2019
571e229
Fix chdir spacing in asterisk.yml
m-anish Jan 17, 2019
5052266
Asterisk: fix playbook syntax
m-anish Jan 17, 2019
b0e9d19
Fix asterisk source tarball extraction
m-anish Jan 17, 2019
6ab5321
Asterisk - Installed aptitude. Fix chown command
m-anish Jan 17, 2019
25702f4
Asterisk - fix file ownership and group permissions
m-anish Jan 17, 2019
490812e
Initial stab at installing FreePBX
m-anish Jan 17, 2019
1bd780e
More FreePBX fixes
m-anish Jan 17, 2019
9f27765
Update FreePBX installation path
m-anish Jan 17, 2019
c710632
Add checks to install pbx only when sugarizer is absent and nodejs ve…
m-anish Jan 18, 2019
85e03c1
comment out redundant variables from pbx/defaults/main.yml
m-anish Jan 18, 2019
01cfb3f
Add freepbx.conf apache file
m-anish Jan 18, 2019
e66104a
Fix freepbx.yml playbook
m-anish Jan 18, 2019
5b41e63
Freepbx - Add libapache2-mpm-itk as a dependency
m-anish Jan 18, 2019
d1be5a4
Add freepbx_install_dir variable to defaults/main.yml
m-anish Jan 18, 2019
4a544ab
Stop enabling/disabling asterisk independently, as it will be handled…
m-anish Jan 18, 2019
759160c
Use freepbx_install_dir variable in freepbx.conf.j2 apache2 template
m-anish Jan 18, 2019
4bd9cc2
Freepbx task: Copy apache file; use freepbx_install_dir variable
m-anish Jan 18, 2019
2f8b08d
Fix indentation in asterisk.yml playbook
m-anish Jan 18, 2019
e884066
Fix debug syntax in pbx/tasks/main.yml
m-anish Jan 18, 2019
e7a0f90
Create freepbx systemd service
m-anish Jan 18, 2019
235284a
Add commented out nodejs_version variable near the pbx flags in vars
m-anish Jan 18, 2019
65a3b02
PBX: Dont install nodejs if incorrect version is chosen
m-anish Jan 18, 2019
5ccf7f3
PBX: fix debug messages
m-anish Jan 18, 2019
61f63e5
Fix nodejs installation condition in pbx
m-anish Jan 18, 2019
8b219b6
Remove unneeded register commands in freepbx.yml playbook
m-anish Jan 18, 2019
72866c7
asterisk.yml, optimze
m-anish Jan 18, 2019
6f31339
pbx/defaults/main.yml: remove deprecated code
m-anish Jan 18, 2019
8dbc4fe
freepbx.yml optimize
m-anish Jan 19, 2019
ed5a683
Add a README to PBX role
m-anish Jan 19, 2019
4dcad92
pbx/defaults/main.yml: Add chan_dongle variables, remove unneeded lib…
m-anish Jan 19, 2019
5e68755
Add chan_dongle.yml
m-anish Jan 19, 2019
2a30b22
Include chan_dongle.yml in asterisk.yml
m-anish Jan 19, 2019
983efe5
PBX: Update README.rst with chan_dongle information
m-anish Jan 19, 2019
a8fa325
Add asterisk_chan_dongle flag to conditionally allow its install
m-anish Jan 19, 2019
e7d842a
Fix and optimize chan_dongle.yml
m-anish Jan 19, 2019
34c0c05
Add asterisk_chan_dongle flag to vars
m-anish Jan 19, 2019
31e5a79
Add make samples to asterisk.yml
m-anish Jan 19, 2019
8b7da40
Add make basic-pbx to asterisk.yml
m-anish Jan 19, 2019
03540d1
Fix asterisk.yml playbook
m-anish Jan 19, 2019
1f254f8
fix chan_dongle.yml playbook - unzip command
m-anish Jan 19, 2019
3e5aae4
Fix chan_dongle.yml again
m-anish Jan 19, 2019
2e9dcb2
chan_dongle fix mv src path
m-anish Jan 19, 2019
92529b8
chan_dongle fix dest path in mv
m-anish Jan 19, 2019
b21251d
chandongle use rsync instead of mv
m-anish Jan 19, 2019
2693605
chan_dongle properly extract asterisk version
m-anish Jan 19, 2019
2b443ce
fix missing freepbx_src
m-anish Jan 19, 2019
c31046b
remove make basic-pbx from asterisk.yml as it messes up /etc/asterisk…
m-anish Jan 19, 2019
3475982
PBX Fail if proper nodejs version is not set
m-anish Jan 19, 2019
75e4f78
Fix message in pbx/tasks/main.yml
m-anish Jan 19, 2019
e44bdc7
Make freepbx.conf apache2 file more secure
m-anish Jan 19, 2019
8367b6c
chan_dongle, copy dongle.conf over
m-anish Jan 19, 2019
9b19f57
Fix syntax in debug msg, pbx/tasks/main.yml
m-anish Jan 20, 2019
379dd8d
Freepbx: Explicitly set asterisk db credentials
m-anish Jan 20, 2019
aa8f642
Add make config to asterisk.yml
m-anish Jan 20, 2019
1f3c886
Dont let freepbx take over sessions directory
m-anish Jan 20, 2019
7713b6d
Authenticate db creation with mysql root user
m-anish Jan 20, 2019
8000534
Run FreePBX php sessions in their own directory, to circumvent owners…
m-anish Jan 20, 2019
d9f76f7
Do not install freepbx by default in BIG install
m-anish Jan 20, 2019
425df6b
Add pbx and pbx.lan to /etc/hosts
m-anish Jan 25, 2019
7b25c99
Add support for debian 9.7
m-anish Feb 7, 2019
5460e05
PBX: Update README.rst
m-anish Feb 7, 2019
cf16721
Update README.rst
holta Feb 9, 2019
f2e6b0e
Update local_vars_min.yml
holta Feb 9, 2019
b12b2c7
Update local_vars_medium.yml
holta Feb 9, 2019
6cae8dd
Update local_vars_big.yml
holta Feb 9, 2019
ef99b88
Update default_vars.yml
holta Feb 9, 2019
ddd2678
Update freepbx_dependencies.yml
holta Feb 9, 2019
a62e77c
Update main.yml
holta Feb 9, 2019
71a6b6c
Update main.yml
holta Feb 9, 2019
f262774
Update main.yml
holta Feb 9, 2019
4d13eff
Update asterisk.yml
holta Feb 9, 2019
c2cdd03
Update main.yml
holta Feb 9, 2019
384230d
Update asterisk.yml
holta Feb 9, 2019
190b0d1
Update freepbx.yml
holta Feb 9, 2019
5058ead
Update main.yml
holta Feb 9, 2019
74f29f5
Update main.yml
holta Feb 9, 2019
956294c
Update main.yml
holta Feb 9, 2019
e2a5d3d
Update main.yml
holta Feb 9, 2019
ed8fe00
Update main.yml
holta Feb 9, 2019
b612937
Update main.yml
holta Feb 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
43 changes: 43 additions & 0 deletions roles/pbx/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
===============
PBX README
===============

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
nodejs_version: 10.x

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

As a dependency the following *must* be set::

sugarizer_install: False
sugarizer_enabled: False

After installing PBX as part IIAB, please log in to http://pbx.lan and proceed with inital configuration.

You can monitor the PBX service with command::

systemctl status freepbx

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

The asterisk and freepbx playbooks have been heavily inspired by the work `here <https://github.com/Yannik/ansible-role-asterisk>`_ and `here <https://github.com/Yannik/ansible-role-freepbx>`_.
Dependencies
------------

1. This playbooks compiles and installs asterisk and freepbx from source, so running this feature involves significant bandwidth and compute time.
2. This playbook is also incompatible with sugarizer, and nodejs-8.x. Therefore if either of those are set to be install, this playbook will gracefully fail with a message requesting the user to fix those incompatibilites.
23 changes: 23 additions & 0 deletions roles/pbx/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pbx_install: False
pbx_enabled: False
pbx_installed: False
asterisk_chan_dongle: 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: Install aptitude (otherwise install_prereq fails)
package:
name: aptitude
state: latest

- name: Asterisk - Ensure all dependencies are resolved
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'
command: make
args:
chdir: "{{ asterisk_src_dir }}"
creates: "defaults.h"

- name: Asterisk - install
command: make install
args:
chdir: "{{ asterisk_src_dir }}"
creates: "/usr/sbin/asterisk"

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

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

- name: Asterisk - 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 directory ownership
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"