2021-08-05 03:14:24 +00:00
# https://wiki.freepbx.org/display/FOP/Installing+FreePBX+16+on+Debian+10.9
# https://computingforgeeks.com/how-to-install-asterisk-16-with-freepbx-15-on-ubuntu-debian/
2021-08-05 18:10:19 +00:00
# RPi: http://mghadam.blogspot.com/2021/03/install-asterisk-18-freepbx-15-on.html
2021-08-05 23:50:44 +00:00
# 2012-2017: http://www.raspberry-asterisk.org
2021-08-05 03:14:24 +00:00
2019-01-17 10:32:58 +00:00
- name : FreePBX - Install dependencies
include : freepbx_dependencies.yml
2021-08-04 13:49:54 +00:00
- name : FreePBX - Download {{ freepbx_url }}/{{ freepbx_src_file }} to {{ downloads_dir }}
2019-01-17 10:32:58 +00:00
get_url :
url : "{{ freepbx_url }}/{{ freepbx_src_file }}"
2021-08-04 13:49:54 +00:00
dest : "{{ downloads_dir }}" # e.g. /opt/iiab/downloads/freepbx-16.0-latest.tgz
2019-01-17 10:32:58 +00:00
timeout : "{{ download_timeout }}"
2020-10-16 20:46:19 +00:00
when : internet_available
2019-01-17 10:32:58 +00:00
2019-01-18 08:03:01 +00:00
- name : FreePBX - Check for {{ downloads_dir }}/{{ freepbx_src_file }}
2019-01-17 10:32:58 +00:00
stat :
path : "{{ downloads_dir }}/{{ freepbx_src_file }}"
2019-01-19 14:43:04 +00:00
register : freepbx_src
2019-01-17 10:32:58 +00:00
2019-01-18 08:03:01 +00:00
- name : FreePBX - FAIL (force Ansible to exit) IF {{ downloads_dir }}/{{ freepbx_src_file }} doesn't exist
2019-01-17 10:32:58 +00:00
fail :
2021-08-04 13:49:54 +00:00
msg : "{{ downloads_dir }}/{{ freepbx_src_file }} is REQUIRED to install FreePBX."
2019-01-17 10:32:58 +00:00
when : not freepbx_src.stat.exists
2021-08-04 13:49:54 +00:00
- name : FreePBX - Create source dir {{ freepbx_src_dir }}
2021-08-03 04:40:38 +00:00
file :
2021-08-04 09:34:19 +00:00
path : "{{ freepbx_src_dir }}" # /opt/iiab/freepbx
2019-01-17 10:32:58 +00:00
state : directory
2021-08-04 13:49:54 +00:00
- name : FreePBX - Extract to source dir (root:root)
2021-08-03 04:40:38 +00:00
unarchive :
2019-01-17 10:32:58 +00:00
src : "{{ downloads_dir }}/{{ freepbx_src_file }}"
dest : "{{ freepbx_src_dir }}"
owner : root
group : root
extra_opts : [ --strip-components=1]
2019-01-19 04:38:47 +00:00
creates : "{{ freepbx_src_dir }}/install"
2019-01-17 10:32:58 +00:00
2021-08-04 13:49:54 +00:00
# 2021-08-04: FreePBX 16 no longer needs this FreePBX 15 patch
# - name: FreePBX - Patch FreePBX source - IIAB Bug 1685
# patch:
# src: roles/pbx/templates/71-freepbx-framework.patch
# dest: "{{ freepbx_src_dir }}/amp_conf/htdocs/admin/libraries/BMO/Framework.class.php"
# 2021-08-04: FreePBX 16 no longer needs this FreePBX 15 patch
# - name: FreePBX - Patch FreePBX source - wants [] not {}
# patch:
# src: roles/pbx/templates/pbx.patch
# dest: "{{ freepbx_src_dir }}/amp_conf/htdocs/admin/libraries/Composer/vendor/neitanod/forceutf8/src/ForceUTF8/Encoding.php"
2019-05-22 03:23:41 +00:00
2020-08-24 19:03:29 +00:00
2021-08-05 03:14:24 +00:00
# 2021-08-04: systemd service 'asterisk' is Enabled but Not Active at this point -- LET'S EXPERIMENT
# - name: FreePBX - Disable & Stop 'asterisk' systemd service
# systemd:
# daemon_reload: yes
# name: asterisk
# enabled: no
# state: stopped
2019-01-17 10:32:58 +00:00
2021-08-05 23:50:44 +00:00
# 2021-08-05: Asterisk's systemd / systemctl support is getting there but Very
2021-08-06 00:09:48 +00:00
# Imperfect (even when compiled in, as a result of package 'libsystemd-dev' at
2021-08-06 02:55:18 +00:00
# top of asterisk.tml) so let's follow these "official" instructions for now:
2021-08-05 23:50:44 +00:00
- name : FreePBX - Run 'update-rc.d -f asterisk remove' similar to 'systemctl disable asterisk' giving FreePBX full control during boot - not strictly required but recommended by https://wiki.freepbx.org/display/FOP/Installing+FreePBX+16+on+Debian+10.9
command : update-rc.d -f asterisk remove
2021-08-04 09:34:19 +00:00
- name : FreePBX - Add MySQL user ({{ asterisk_db_user }})
2019-01-20 05:41:28 +00:00
mysql_user :
name : "{{ asterisk_db_user }}"
password : "{{ asterisk_db_password }}"
priv : "{{ asterisk_db_dbname }}.*:ALL/{{ asterisk_db_cdrdbname }}.*:ALL"
2021-08-04 09:06:12 +00:00
# login_host: "{{ asterisk_db_host }}"
# login_user: root
# login_password: "{{ mysql_root_password }}"
2019-01-20 05:41:28 +00:00
host : "{{ (asterisk_db_host == 'localhost') | ternary('localhost', ansible_default_ipv4.address) }}"
state : present
2021-08-04 09:34:19 +00:00
- name : FreePBX - Add MySQL db ({{ asterisk_db_dbname }})
2019-01-20 05:41:28 +00:00
mysql_db :
name : "{{ asterisk_db_dbname }}"
encoding : utf8
collation : utf8_general_ci
2021-08-04 09:06:12 +00:00
# login_host: "{{ asterisk_db_host }}"
# login_user: root
# login_password: "{{ mysql_root_password }}"
2019-01-20 05:41:28 +00:00
state : present
2021-08-04 09:34:19 +00:00
- name : FreePBX - Add cdr MySQL db ({{ asterisk_db_cdrdbname }})
2019-01-20 05:41:28 +00:00
mysql_db :
name : "{{ asterisk_db_cdrdbname }}"
encoding : utf8
collation : utf8_general_ci
login_host : "{{ asterisk_db_host }}"
state : present
2021-08-05 03:38:37 +00:00
- name : FreePBX - Create new php sessions dir /var/lib/php/asterisk_sessions/ - SEE 'php_value session.save_path /var/lib/php/asterisk_sessions/' IN pbx/templates/freepbx.conf.j2
2021-08-03 04:40:38 +00:00
file :
path : /var/lib/php/asterisk_sessions/
2019-01-20 12:45:22 +00:00
state : directory
2021-08-04 09:34:19 +00:00
- name : FreePBX - Set ownership for new php sessions dir (asterisk:asterisk)
2021-08-03 04:40:38 +00:00
file :
dest : /var/lib/php/asterisk_sessions/
owner : asterisk
2019-01-20 12:45:22 +00:00
group : asterisk
recurse : yes
2021-08-03 04:40:38 +00:00
2021-08-05 03:14:24 +00:00
- name : "FreePBX - Populate /etc/asterisk/freepbx_chown.conf to prevent 'fwconsole chown' takeover of /var/lib/php/sessions - and possibly later /etc/freepbx.conf, /var/log/asterisk/freepbx.log, /var/spool/asterisk/cache"
blockinfile :
content : |
[ blacklist]
directory = /var/lib/php/sessions
2021-08-05 04:05:32 +00:00
marker : "; {mark} ANSIBLE MANAGED BLOCK"
2021-08-05 03:14:24 +00:00
dest : /etc/asterisk/freepbx_chown.conf
owner : asterisk
group : asterisk
create : yes
# 2021-08-04: FreePBX 16 no longer needs this FreePBX 15 patch
# - name: FreePBX - Patch FreePBX source - disable get_magic_quotes_gpc()
# patch:
# src: roles/pbx/templates/pbx2.patch
# dest: "{{ freepbx_install_dir }}/admin/libraries/view.functions.php"
2020-08-24 05:25:56 +00:00
2021-08-05 03:14:24 +00:00
2021-08-06 02:04:26 +00:00
- name : FreePBX - 2-step install (just run once) - CAN TAKE 3-12 MIN OR LONGER!
2021-08-04 13:49:54 +00:00
command : "{{ item }}"
2019-01-17 10:32:58 +00:00
args :
2019-01-17 11:55:03 +00:00
chdir : "{{ freepbx_src_dir }}"
2021-08-05 04:16:56 +00:00
creates : "{{ freepbx_install_dir }}" # /var/www/html/freepbx
2021-08-04 13:49:54 +00:00
with_items :
- ./start_asterisk start
- ./install -n --webroot {{ freepbx_install_dir }} --dbuser {{ asterisk_db_user }} --dbpass {{ asterisk_db_password }} --dbname {{ asterisk_db_dbname }} --cdrdbname {{ asterisk_db_cdrdbname }}
2021-08-07 02:44:30 +00:00
2021-08-07 03:21:17 +00:00
- name : "2021-08-06: Does 'fwconsole stop' gracefully stop both Asterisk processes, to avoid #2915 \"Unable to run Pre-Asterisk hooks, because Asterisk is already running\" in 'journalctl -u freepbx' logs?"
2021-08-07 02:44:30 +00:00
command : fwconsole stop
# command: "{{ item }}"
# with_items:
# # - ./start_asterisk stop
# # - killall -9 safe_asterisk # 2021-08-05: These 2 lines from PR #2912 attempt a brute force workaround for #2908 annoyances on 1st install,
# # - killall -9 asterisk # i.e. 'systemctl status freepbx' showing "Unable to run Pre-Asterisk hooks, because Asterisk is already running"
# # - /usr/sbin/asterisk -rx "core stop gracefully"
# # - fwconsole reload
# - fwconsole stop
# # - fwconsole restart
# # - fwconsole ma disablerepo commercial
# # - fwconsole ma installall
# # - fwconsole ma delete firewall
# # - fwconsole reload
# # - fwconsole restart
2021-08-05 03:14:24 +00:00
2021-08-07 03:21:17 +00:00
# 2021-08-06: This stanza might be removed in future, if Asterix/FreePBX fix
# this install glitch in a future release? FYI #2908, #2912, #2913 attempts
# didn't work. This workaround helps: https://github.com/iiab/iiab/pull/2915
# - name: FreePBX - Run 'systemctl restart freepbx' TWICE (THIS IS 1 OF 2) to get past 'systemctl status freepbx' glitch "Unable to run Pre-Asterisk hooks, because Asterisk is already running"
# systemd:
# daemon_reload: yes
# name: freepbx
# enabled: yes
# state: restarted
2021-08-05 03:14:24 +00:00
# - name: 'FreePBX - fix file permissions for NGINX: /etc/freepbx.conf (0644), /var/log/asterisk/freepbx.log (0666)'
# file:
# #state: file
# path: "{{ item.path }}"
# mode: "{{ item.mode }}"
# with_items:
# - { path: '/etc/freepbx.conf', mode: u=rw,g=r,o=r } # 2021-08-04: LATER ENDS UP AS 0660
# - { path: '/var/log/asterisk/freepbx.log', mode: u=rw,g=rw,o=rw } # 2021-08-04: LATER ENDS UP AS 0664
# - name: 'FreePBX - fix dir permissions for NGINX: /var/spool/asterisk/cache (0777)'
# file:
# state: directory
# path: "{{ item }}"
# mode: u=rwx,g=rwx,o=rwx # 2021-08-04: MOST CONTENT THEREIN ENDS UP AS asterisk:asterisk 664 (files) & 775 (dirs)
# # recurse: yes # Probably Doesn't Help?
# with_items:
# # - /var/www/html/freepbx/admin/assets/less/cache
# - /var/spool/asterisk/cache
2020-08-24 19:19:04 +00:00
2021-08-05 20:50:24 +00:00
- name : FreePBX - Install /etc/odbc.ini from template (root:root, 0644 by default) - in future consider compiling ODBC driver for aarch64 per http://mghadam.blogspot.com/2021/03/install-asterisk-18-freepbx-15-on.html ?
2019-01-17 11:55:03 +00:00
template :
2021-08-05 03:14:24 +00:00
src : odbc.ini
dest : /etc/
2019-01-18 08:03:01 +00:00
2021-08-05 03:14:24 +00:00
- name : FreePBX - Install /etc/systemd/system/freepbx.service from template (root:root, 0644 by default)
2021-08-04 13:49:54 +00:00
template :
2021-08-05 03:14:24 +00:00
src : freepbx.service
dest : /etc/systemd/system/
2021-08-04 13:49:54 +00:00
2021-08-07 03:21:17 +00:00
- name : "2021-08-06: Try \"$amp_conf['AMPASTERISKWEBUSER'] = 'www-data';\" in /etc/freepbx.conf for #2916 registration cron fix ?'"
lineinfile :
path : /etc/freepbx.conf
insertafter : '^<\?php$' # Match exact line '<?php'
line : "$amp_conf['AMPASTERISKWEBUSER'] = 'www-data';"
2021-08-06 23:54:26 +00:00
# - name: FreePBX - Install /etc/apache2/sites-available/freepbx.conf from template ({{ apache_user }}:{{ apache_user }}, 0644 by default)
# template:
# src: freepbx.conf.j2
# dest: /etc/apache2/sites-available/freepbx.conf
# owner: "{{ apache_user }}" # www-data
# group: "{{ apache_user }}"
# - name: FreePBX - Add directive "Listen {{ pbx_http_port }}" to /etc/apache2/ports.conf
# lineinfile:
# path: /etc/apache2/ports.conf
# line: "Listen {{ pbx_http_port }}"
# # insertafter: Listen 80