---
# file: roles/php/tasks/msodbc.yml

- name: Apt Key
  apt_key:
    url: https://packages.microsoft.com/keys/microsoft.asc
    state: present

- name: Apt Repository
  apt_repository:
    repo: deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/prod {{ ansible_distribution_release }} main
    state: present
    mode: 0644

- name: Accept licenses
  debconf:
    name: "{{ item }}-installer"
    question: "{{ item }}/accept_eula"
    value: "true"
    vtype: "select"
  with_items:
    - msodbcsql
    - mssql-tools

- name: Install Packages
  apt:
    pkg: '{{ packages }}'
    state: present
    update_cache: yes
  vars:
    packages:
      - msodbcsql
      - mssql-tools
      - unixodbc-dev
  notify:
    - Restart Apache

- name: PHP | Install PECL packages
  shell: pecl install --soft {{ item }}
  with_items:
    - sqlsrv
    - pdo_sqlsrv

- name: Configuration files
  copy:
    content: extension={{ item }}.so
    dest: /etc/{{ php_base_dir }}/{{ php_conf_dir }}/{{ item }}.ini
    owner: root
    group: root
    mode: 0644
  with_items:
    - sqlsrv
    - pdo_sqlsrv
  notify:
    - Restart Apache

- name: Enable extensions
  shell: phpenmod {{ item }}
  with_items:
    - sqlsrv
    - pdo_sqlsrv
  notify:
    - Restart Apache
