---

- name: Configure vsftpd
  template: src=vsftpd/{{ item }}.j2 dest=/etc/vsftpd/{{ item }}
  loop:
    - user_list
    - vsftpd.conf
    - chroot_list
  notify: restart vsftpd
  tags: fpbx

- name: Deploy PAM config for vsftpd
  template: src=vsftpd/pam.j2 dest=/etc/pam.d/vsftpd
  tags: fpbx

- name: Deploy configuration
  template: src={{ item }}.j2 dest=/etc/{{ item }}
  loop:
    - freepbx.conf
  notify:
    - reload freepbx
    - fpbx chown
  tags: fpbx

- name: Configure manager.conf and extensions.conf
  lineinfile:
    path: "{{ item.file }}"
    regexp: '^{{ item.param }}\s*=.*'
    line: '{{ item.param }} = {{ item.value }}'
  loop:
    - param: secret
      value: "{{ fpbx_manager_pass }}"
      file: /etc/asterisk/manager.conf
  tags: fpbx

- name: Set amportal settings
  command: /usr/local/bin/fwconsole setting {{ item.param }} {{ item.value }}
  loop:
    - param: AMPMGRUSER
      value: admin
    - param: AMPMGRPASS
      value: "{{ fpbx_manager_pass }}"
    - param: PROXY_ENABLED
      value: "{{ (system_proxy is defined and system_proxy != '') | ternary('TRUE','FALSE') }}"
    - param: PROXY_ADDRESS
      value: "'{{ (system_proxy is defined and system_proxy != '') | ternary(system_proxy,'') }}'"
    - param: AUTHTYPE
      value: "{{ fpbx_auth_type }}"
    - param: PHPTIMEZONE
      value: "{{ system_tz | default('UTC') }}"
    - param: HTTPENABLED
      value: TRUE
    - param: HTTPBINDADDRESS
      value: 0.0.0.0
    - param: HTTPBINDPORT
      value: 8088
    - param: HTTPPREFIX
      value: asterisk
    - param: NODEJSBINDADDRESS
      value: 0.0.0.0
    - param: NODEJSHTTPSBINDADDRESS
      value: 0.0.0.0
  changed_when: False
  tags: fpbx

# Configure httpd / PHP
- import_tasks: ../includes/webapps_webconf.yml
  vars:
    - app_id: freepbx
    - php_version: "{{ fpbx_php_version }}"
    - php_fpm_pool: "{{ fpbx_php_fpm_pool | default('') }}"
  tags: fpbx

- name: Install logrotate config
  template: src=logrotate.conf.j2 dest=/etc/logrotate.d/asterisk
  tags: fpbx

