2015-07-22 14:40:20 +07:00
|
|
|
---
|
2015-07-23 15:40:33 +07:00
|
|
|
|
2022-02-22 19:41:02 +07:00
|
|
|
- name: SHELL | Check if we are in multiple PHP distribution
|
|
|
|
ansible.builtin.shell: set -o pipefail && apt-cache search php xdebug | grep 'php[[:digit:]].[[:digit:]]'
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
register: multiple_php
|
|
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
|
2018-03-18 23:28:57 +07:00
|
|
|
- name: INCLUDE_VARS | Related to OS family
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.include_vars: "OS_Family_{{ ansible_os_family }}.yml"
|
2016-01-22 21:57:29 +07:00
|
|
|
|
2018-03-18 23:28:57 +07:00
|
|
|
- name: INCLUDE_VARS | Related to OS version
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.include_vars: "{{ item }}"
|
2018-10-28 18:29:56 +07:00
|
|
|
with_first_found:
|
|
|
|
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
|
|
|
|
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
|
|
|
|
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
2016-12-08 23:38:10 +07:00
|
|
|
|
2019-12-26 20:13:00 +07:00
|
|
|
- name: SET_FACT | Transform data
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.set_fact:
|
2019-12-26 20:13:00 +07:00
|
|
|
__php_fpm_full_pool: |
|
|
|
|
[
|
|
|
|
{% for p in php_fpm_poold %}
|
|
|
|
{
|
|
|
|
name: "{{ p.name | default(p.pool_name) }}",
|
|
|
|
listen: "{{ p.listen | default(php_version | php_socket(p.name | default(p.pool_name))) }}",
|
|
|
|
user: "{{ p.user | default(php_default_user_group) }}",
|
|
|
|
group: "{% if p.user is defined %}{{ p.group | default(p.user) }}{% else %}{{ p.group | default(php_default_user_group) }}{% endif %}",
|
|
|
|
php_value: {% if p.php_value is defined %}{{ p.php_value | to_nice_json }}{% else %}{}{% endif %},
|
|
|
|
php_admin_value: {% if p.php_admin_value is defined %}{{ p.php_admin_value | to_nice_json }}{% else %}{}{% endif %},
|
|
|
|
{% for k, v in p.items() | list %}
|
|
|
|
{% if k not in ['name', 'pool_name', 'listen', 'user', 'group', 'php_value', 'php_admin_value'] %}
|
|
|
|
{{ k }}: "{{ v }}"{% if not loop.last %},{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
}{% if not loop.last %},{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
]
|
|
|
|
|
|
|
|
- name: SET_FACT | To YAML
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.set_fact:
|
2019-12-26 20:13:00 +07:00
|
|
|
php_fpm_full_pool: "{{ __php_fpm_full_pool | from_yaml }}"
|
|
|
|
|
|
|
|
- name: FILE | Creates ansible facts.d
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.file:
|
2019-12-26 20:13:00 +07:00
|
|
|
path: /etc/ansible/facts.d
|
|
|
|
state: directory
|
2021-09-01 14:57:23 +07:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
2019-12-26 20:13:00 +07:00
|
|
|
|
|
|
|
- name: COPY | Manage facts
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.copy:
|
2019-12-26 20:13:00 +07:00
|
|
|
content: "{ \"fpm_pool\": {{ php_fpm_full_pool | to_nice_json }} }"
|
|
|
|
dest: /etc/ansible/facts.d/hanxhx_php.fact
|
2021-09-01 14:57:23 +07:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2019-12-26 20:13:00 +07:00
|
|
|
register: f
|
2022-10-06 17:14:55 +07:00
|
|
|
tags:
|
|
|
|
- skip_ansible_lint
|
2019-12-26 20:13:00 +07:00
|
|
|
|
|
|
|
- name: SETUP | Gathers new facts
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.setup:
|
2019-12-26 20:13:00 +07:00
|
|
|
when: f.changed
|
|
|
|
tags:
|
|
|
|
- skip_ansible_lint
|
|
|
|
|
2015-07-23 15:40:33 +07:00
|
|
|
- name: APT | Install PHP packages
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.apt:
|
2019-12-26 20:13:00 +07:00
|
|
|
pkg: "{{ pkgs }}"
|
2018-03-18 23:28:57 +07:00
|
|
|
state: present
|
2021-09-01 14:57:23 +07:00
|
|
|
update_cache: true
|
2018-03-18 23:28:57 +07:00
|
|
|
cache_valid_time: 3600
|
2022-02-22 19:41:02 +07:00
|
|
|
install_recommends: false
|
2019-12-26 20:13:00 +07:00
|
|
|
vars:
|
|
|
|
pkgs: "{{ php_packages + php_extra_packages | flatten }}"
|
2022-10-06 17:42:56 +07:00
|
|
|
notify: Restart php-fpm
|
2018-03-19 03:29:47 +07:00
|
|
|
when: ansible_os_family == 'Debian'
|
|
|
|
|
|
|
|
- name: PKGNG | Install PHP packages
|
2021-09-01 14:57:23 +07:00
|
|
|
community.general.pkgng:
|
2019-12-26 20:13:00 +07:00
|
|
|
name: "{{ php_packages + php_extra_packages | flatten | join(',') }}"
|
2022-10-06 17:42:56 +07:00
|
|
|
notify: Restart php-fpm
|
2018-03-19 03:29:47 +07:00
|
|
|
when: ansible_os_family == 'FreeBSD'
|
2015-07-23 15:40:33 +07:00
|
|
|
|
2019-04-19 15:28:00 +07:00
|
|
|
- name: IMPORT_TASKS | PHP-FPM
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.import_tasks: fpm.yml
|
2015-07-23 15:40:33 +07:00
|
|
|
|
2018-03-19 03:29:47 +07:00
|
|
|
- name: LINEINFILE | PHP CLI configuration
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.lineinfile:
|
2018-03-18 23:28:57 +07:00
|
|
|
dest: '{{ php_cli_ini }}'
|
2017-11-10 18:19:39 +07:00
|
|
|
regexp: '^;?{{ item.key }}'
|
|
|
|
line: '{{ item.key }} = {{ item.value }}'
|
2019-01-28 20:46:58 +07:00
|
|
|
loop: "{{ php_ini | combine(php_ini_cli) | dict2items }}"
|
2015-08-28 14:48:25 +07:00
|
|
|
|
2019-04-19 15:28:00 +07:00
|
|
|
- name: IMPORT_TASKS | Xdebug
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.import_tasks: xdebug.yml
|
2015-07-23 15:40:33 +07:00
|
|
|
|
2016-01-22 21:57:29 +07:00
|
|
|
- name: APT | Install and configure opcache
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.import_tasks: opcache.yml
|
2019-01-28 20:46:58 +07:00
|
|
|
|
|
|
|
- name: SERVICE | Ensure PHP-FPM is started
|
2021-09-01 14:57:23 +07:00
|
|
|
ansible.builtin.service:
|
2019-01-28 20:46:58 +07:00
|
|
|
name: '{{ php_fpm_service }}'
|
|
|
|
state: started
|
|
|
|
when: php_install_fpm and ansible_virtualization_type != 'docker'
|
|
|
|
|
2022-10-06 17:14:55 +07:00
|
|
|
- name: BLOCK | Ensure PHP-FPM is started if running on Docker
|
|
|
|
when: php_install_fpm and ansible_virtualization_type == 'docker'
|
|
|
|
block:
|
2019-01-28 20:46:58 +07:00
|
|
|
|
2021-09-01 14:57:23 +07:00
|
|
|
- name: COMMAND | Check if PHP-FPM is started (Docker)
|
|
|
|
ansible.builtin.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)
|
|
|
|
ansible.builtin.command: 'service {{ php_fpm_service }} start'
|
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
when: dps.stdout.find('is not running') != -1
|