- name: "ONLY PHP 7.4 IS SUPPORTED AS OF MAY 2022 -- PLEASE READ: https://github.com/iiab/iiab/tree/master/roles/pbx#readme"
  meta: noop


- name: "Set 'nodejs_install: True' and 'nodejs_enabled: True'"
  set_fact:
    nodejs_install: True
    nodejs_enabled: True

- name: NODEJS - run 'nodejs' role (attempt to install & enable Node.js)
  include_role:
    name: nodejs

- name: FAIL (STOP THE INSTALL) IF 'nodejs_installed is undefined'
  fail:
    msg: "PBX install cannot proceed, as Node.js is not installed."
  when: nodejs_installed is undefined

# - name: FAIL (STOP THE INSTALL) IF 'nodejs_version != "12.x"'
#   fail:
#     msg: "PBX install cannot proceed, as it currently requires Node.js 12.x, whereas nodejs_version is set to {{ nodejs_version }}.  Please check the value of nodejs_version in /opt/iiab/iiab/vars/default_vars.yml, /etc/iiab/local_vars.yml, /opt/iiab/iiab/roles/nodejs, etc."
#   when: nodejs_version != "12.x"


# 2021-08-09: Moved to roles/pbx/tasks/apache.yml

# - name: "Set 'apache_install: True' and 'apache_enabled: True'"
#   set_fact:
#     apache_install: True
#     apache_enabled: True

# - name: APACHE - run 'httpd' role
#   include_role:
#     name: httpd


- name: Install Asterisk
  include_tasks: asterisk.yml
  when: asterisk_installed is undefined

- name: Install FreePBX
  include_tasks: freepbx.yml


# RECORD PBX AS INSTALLED

- name: "Set 'pbx_installed: True'"
  set_fact:
    pbx_installed: True

- name: "Add 'pbx_installed: True' to {{ iiab_state_file }}"
  lineinfile:
    path: "{{ iiab_state_file }}"    # /etc/iiab/iiab_state.yml
    regexp: '^pbx_installed'
    line: 'pbx_installed: True'
