# Pear

- name: pear | install pear packages
  apt: >
    pkg={{ item }} 
    state=installed
    force=yes
  with_items: pkgs_php_pear
  when: ansible_os_family == 'Debian'

- name: pear | install rpm php
  yum: >
    pkg={{ item }} 
    state=latest
  with_items: pkgs_php_pear
  when: ansible_os_family in ['CentOS', 'Fedora', 'OpenSuse', 'RedHat']

# Pear Update / Configuration

- name: pear | update pear packages
  command: pear upgrade

- name: pear | set pear auto-discover
  command: pear config-set auto_discover 1

# Pear Channels 

- name: pear | install channels
  command: pear channel-discover {{ item }}
  with_items: php.pear.channels
  when: php.pear.channels is defined

# Pear Packages 

- name: pear | install packages
  command: pear install {{ php.pear.install_args|default('') }} {{ item }}
  with_items: php.pear.modules
  when: php.pear.modules is defined

# Pear

- name: pear | install pear packages
  apt: >
    pkg={{ item }}
    state=installed
    force=yes
  with_items: pkgs_php_pear
  when: ansible_os_family == 'Debian'

- name: pear | install rpm php
  yum: >
    pkg={{ item }}
    state=latest
  with_items: pkgs_php_pear
  when: ansible_os_family in ['CentOS', 'Fedora', 'OpenSuse', 'RedHat']

# Pear Update / Configuration

- name: pear | update pear packages
  command: pear upgrade

- name: pear | set pear auto-discover
  command: pear config-set auto_discover 1

# Pear Channels

- name: pear | install channels
  command: pear channel-discover {{ item }}
  with_items: php.pear.channels
  when: php.pear.channels is defined
  register: channel_result
  changed_when: "'initialized' not in channel_result.stdout"
  failed_when: "'already initialized' not in channel_result.stdout and 'succeeded' not in  channel_result.stdout"

# Pear Packages

- name: pear | install packages
  command: pear install {{ php.pear.install_args|default('') }} {{ item }}
  with_items: php.pear.modules
  when: php.pear.modules is defined
  register: pear_result
  changed_when: "'already installed' not in pear_result.stdout"
  failed_when: "'already installed' not in pear_result.stdout and 'install ok' not in pear_result.stdout and pear_result.stderr"

Make PEAR a little smarter.
Make PEAR a little smarter.

This lets PEAR still work if provisioning is re-run. It seems to work as-is even though
it's an array; at least, it has for me. Inspired by:
http://stackoverflow.com/questions/20804004/installing-php-pear-packages-via-ansible-with-idempotency
https://github.com/geerlingguy/ansible-role-php-pear/blob/master/tasks/main.yml

GH-101: Use more accurate check.

GH-101: Remove trailing whitespace.

GH-101: Fix failure on first run.
