ansible-role-php-fpm/tasks/main.yml

110 lines
4.3 KiB
YAML

---
# php as a standalone service
- name: Install the repository if required, and the packages
block:
- name: Install the Ubuntu PHP PPA
apt_repository: repo={{ php_ppa }} state=present update_cache=yes
when: php_from_ppa
- name: Remove the Ubuntu PHP PPA
apt_repository: repo={{ php_ppa }} state=absent update_cache=yes
when: not php_from_ppa
- name: Install the php-fpm package
apt: pkg={{ php_fpm_packages }} state=present update_cache=yes cache_valid_time=3600
- name: Install additional php packages
apt: pkg={{ php_additional_packages | default([]) }} state=latest update_cache=yes cache_valid_time=3600
tags: [ 'php', 'php_ppa' ]
- name: Configure PHP
block:
- name: Set the timezone if we have one
ini_file: dest={{ phpfpm_base_dir }}/php.ini section=Date option=date.timezone value={{ timezone }} backup=yes
when: timezone is defined
notify: Reload php-fpm
- name: Modify the global php settings
ini_file:
dest: '{{ phpfpm_base_dir }}/php.ini'
section: '{{ item.section | default("PHP") }}'
option: '{{ item.option }}'
value: '{{ item.value }}'
state: '{{ item.state | default("present") }}'
with_items: '{{ php_global_settings | default([]) }}'
notify: Reload php-fpm
- name: Modify the global php cli settings
ini_file:
dest: '{{ phpfpm_cli_dir }}/php.ini'
section: "{{ item.section | default('PHP') }}"
option: '{{ item.option }}'
value: '{{ item.value }}'
state: "{{ item.state | default('present') }}"
with_items: '{{ php_cli_global_settings | default([]) }}'
- name: Activate the memcache sessions support and redundancy if required
action: configfile path={{ phpfpm_base_dir }}/conf.d/20-memcache.ini key={{ item.prop }} value='{{ item.value }}'
when: phpfpm_use_memcache_redundancy_sessions
with_items: '{{ memcache_session }}'
notify: Reload php-fpm
- name: remove php-fpm default pool
file: dest={{ phpfpm_base_dir }}/pool.d/www.conf state=absent
when: phpfpm_remove_default_pool
notify: Restart php-fpm
- name: Create the users under the php-fpm processes will run
user: name={{ item.user }} comment="{{ item.user }}" home=/dev/null createhome=no shell={{ item.shell | default('/usr/sbin/nologin') }} system=yes
with_items: '{{ phpfpm_pools }}'
when: phpfpm_create_users
notify: Restart php-fpm
tags: [ 'php', 'fpm_pool' ]
- name: Create the directories where to store the sessions files. One for each pool
file: dest={{ phpfpm_session_prefix }}/{{ item.pool_name }} owner={{ item.user }} group=root mode=0750 state=directory
with_items: '{{ phpfpm_pools }}'
when:
- phpfpm_session_prefix is defined
- phpfpm_use_default_template
tags: [ 'php', 'fpm_pool' ]
- name: Create the directories where to store the log files
file: dest={{ phpfpm_logdir }} owner=root group=root mode=0750 state=directory
tags: [ 'php', 'fpm_pool' ]
- name: Install the php-fpm logrotate file
template: src=php-fpm.logrotate.j2 dest=/etc/logrotate.d/php-fpm owner=root group=root mode=0444
tags: [ 'php', 'fpm_conf' ]
- name: Install the php-fpm main config file
template: src=php-fpm.conf.j2 dest={{ phpfpm_base_dir }}/php-fpm.conf owner=root group=root mode=0444
notify: Restart php-fpm
- name: Install the php-fpm pools
template: src=php-fpm-pool.conf.j2 dest={{ phpfpm_base_dir }}/pool.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_conf', 'fpm_pool', 'fpm_pool_conf' ]
- name: Manage the php-fpm service
block:
- name: Create the systemd override directory
file: dest=/etc/systemd/system/php{{ php_version }}-fpm.service.d state=directory owner=root group=root mode='0755'
- name: Install the unit override file
template: src=php-fpm.service.override.conf.j2 dest=/etc/systemd/system/php{{ php_version }}-fpm.service.d/override.conf owner=root group=root mode='0644'
- name: Ensure that the php-fpm service is started and enabled
service: name=php{{ php_version }}-fpm state=started enabled=yes
when: phpfpm_service_enabled
- name: Ensure that the php-fpm service is stopped and disabled
service: name=php{{ php_version }}-fpm state=stopped enabled=no
when: not phpfpm_service_enabled
tags: php