ansible-php/tasks/main.yml

113 lines
3.4 KiB
YAML

---
- name: SET_FACT | Bypass https://github.com/ansible/ansible/issues/19874
set_fact:
ansible_distribution_release: 'buster'
when: ansible_facts.distribution_major_version == "buster/sid"
- name: INCLUDE_VARS | Related to OS family
include_vars: "OS_Family_{{ ansible_os_family }}.yml"
- name: INCLUDE_VARS | Related to OS version
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- name: SET_FACT | Transform data
set_fact:
__php_fpm_full_pool: |
[
{% for p in php_fpm_poold %}
{
name: "{{ p.name | default(p.pool_name) }}",
listen: "{{ item.listen | default(php_version | php_socket(p.name | default(p.pool_name))) }}",
user: "{{ item.user | default(php_default_user_group) }}",
group: "{{ item.group | default(php_default_user_group) }}",
listen_owner: "{{ item.listen_owner | default(php_default_user_group) }}",
listen_group: "{{ item.listen_owner | default(php_default_user_group) }}",
{% for k, v in p.items() %}
{% if k not in ['name', 'pool_name', 'listen', 'user', 'group', 'listen_owner'] %}
{{ k }}: "{{ v }}"{% if not loop.last %},{% endif %}
{% endif %}
{% endfor %}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
- name: SET_FACT | To YAML
set_fact:
php_fpm_full_pool: "{{ __php_fpm_full_pool | from_yaml }}"
- name: FILE | Creates ansible facts.d
file:
path: /etc/ansible/facts.d
state: directory
recurse: yes
- name: COPY | Manage current repositories
copy:
content: "{ \"php_fpm_full_pool\": {{ php_fpm_full_pool | to_json }} }"
dest: /etc/ansible/facts.d/php_fpm_pool.fact
- debug: var=php_fpm_full_pool
- fail: msg='ok'
- name: APT | Install PHP packages
apt:
pkg: "{{ item }}"
state: present
update_cache: yes
cache_valid_time: 3600
loop: "{{ php_packages + php_extra_packages | flatten }}"
notify: restart php-fpm
when: ansible_os_family == 'Debian'
- name: PKGNG | Install PHP packages
pkgng:
name: "{{ item }}"
loop: "{{ php_packages + php_extra_packages | flatten }}"
notify: restart php-fpm
when: ansible_os_family == 'FreeBSD'
- name: IMPORT_TASKS | PHP-FPM
import_tasks: fpm.yml
- name: LINEINFILE | PHP CLI configuration
lineinfile:
dest: '{{ php_cli_ini }}'
regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}'
loop: "{{ php_ini | combine(php_ini_cli) | dict2items }}"
- name: IMPORT_TASKS | Xdebug
import_tasks: xdebug.yml
- name: APT | Install and configure opcache
import_tasks: opcache.yml
- name: SERVICE | Ensure PHP-FPM is started
service:
name: '{{ php_fpm_service }}'
state: started
when: php_install_fpm and ansible_virtualization_type != 'docker'
- block:
- name: COMMAND | Check if PHP-FPM is started (Docker)
command: 'service {{ php_fpm_service }} status'
args:
warn: false
register: dps
changed_when: false
failed_when: false
- name: COMMAND | Ensure PHP-FPM is started (Docker)
command: 'service {{ php_fpm_service }} start'
args:
warn: false
when: dps.stdout.find('is not running') != -1
when: php_install_fpm and ansible_virtualization_type == 'docker'