---
- name: install the php-fpm package from RH SCL. We assume that apache is the web server of choice.
  yum: pkg={{ item }} state={{ pkg_state }}
  with_items: php_rh_scl_packages
  when: php_install_rh_scl
  tags: php

- name: Set the timezone if we defined one, RH SCL version
  ini_file: dest={{ php_rh_scl_confdir }}/php.ini section=Date option=date.timezone value={{ timezone }} backup=yes
  when:
    - timezone is defined
    - php_install_rh_scl
  notify: Reload php-fpm
  tags: [ 'php', 'php_ini' ]

- name: Set some other php.ini values
  ini_file: dest={{ php_rh_scl_confdir }}/php.ini section=Date option={{ item.option }} value={{ item.value }} backup=yes
  with_items: php_ini_values
  when:
    - php_ini_values is defined
    - php_install_rh_scl
  notify: Reload php-fpm
  tags: [ 'php', 'php_ini' ]

- name: Remove the standard www pool if needed, RH SCL version
  copy: content="" dest={{ php_rh_scl_confdir }}/php-fpm.d/www.conf owner=root group=root mode=0444
  when:
    - phpfpm_remove_default_pool
    - php_install_rh_scl
  notify: Restart php-fpm
  tags: [ 'php', 'fpm_pool' ]

- name: Create the base sessions directory, RH SCL version
  file: dest={{ phpfpm_rh_scl_session_prefix }} owner=root group=root mode=0755 state=directory
  when: phpfpm_use_default_template
  tags: [ 'php', 'fpm_pool', 'php_session' ]

- name: Create the directories where to store the sessions files. One for each pool, RH SCL version
  file: dest={{ phpfpm_rh_scl_session_prefix }}/{{ item.pool_name }} owner={{ item.user }} group={{ item.group }} mode=0750 state=directory
  with_items: phpfpm_pools
  when: phpfpm_use_default_template
  tags: [ 'php', 'fpm_pool', 'php_session' ]

- name: Install the php-fpm main config file, RH SCL version
  template: src=php-fpm.conf.j2 dest={{ php_rh_scl_confdir }}/php-fpm.conf owner=root group=root mode=0444
  notify: Restart php-fpm
  tags: [ 'php', 'fpm_pool', 'fpm_conf' ]

- name: Install the php-fpm pools, RH SCL version
  template: src=php-fpm-pool.conf.j2 dest={{ php_rh_scl_confdir }}/php-fpm.d/{{ item.pool_name }}.conf owner=root group=root mode=0444
  with_items: phpfpm_pools
  when: phpfpm_use_default_template
  notify: Restart php-fpm
  tags: [ 'php', 'fpm_pool', 'fpm_conf', 'fpm_pool_conf' ]

- name: Ensure that php-fpm is running and enabled, RH SCL version
  service: name='rh-php{{ php_rh_scl_shortver }}-php-fpm' state=started enabled=yes
  when: phpfpm_service_enabled
  ignore_errors: True
  tags: php

- name: Ensure that php-fpm is stopped if it is not meant to be running, RH SCL version
  service: name='rh-php{{ php_rh_scl_shortver }}-php-fpm' state=stopped enabled=no
  when: not phpfpm_service_enabled
  ignore_errors: True
  tags: php