- name: Install
  apt: pkg="php5.6-dev" state=present
  when: php.pecl_packages is defined

- name: Install Package
  shell: echo "\n\n\n\n\n\n\n\n\n" | pecl install {{ item.package }}
  register: pecl_result
  changed_when: "'already installed' not in pecl_result.stdout"
  failed_when: "pecl_result.stderr or ('ERROR' in pecl_result.stdout)"
  with_items: '{{ php.pecl_packages }}'
  when: php.pecl_packages is defined

- name: Create extension .ini file
  template: >
    src="extension.tpl"
    dest="/etc/php/5.6/mods-available/{{ item.name }}.ini"
    owner="root"
    group="root"
    mode=0644
  with_items: '{{ php.pecl_packages }}'
  when: php.pecl_packages is defined

- name: Enable extension for FPM
  file:
    src: "/etc/php/5.6/mods-available/{{ item.name }}.ini"
    dest: "/etc/php/5.6/fpm/conf.d/20-{{ item.name }}.ini"
    state: link
  with_items: '{{ php.pecl_packages }}'
  when: php.pecl_packages is defined

- name: Enable extension for CLI
  file:
    src: "/etc/php/5.6/mods-available/{{ item.name }}.ini"
    dest: "/etc/php/5.6/cli/conf.d/20-{{ item.name }}.ini"
    state: link
  with_items: '{{ php.pecl_packages }}'
  when: php.pecl_packages is defined
