Skip to content

Commit

Permalink
🐛 Fix multiple PHP versions install
Browse files Browse the repository at this point in the history
With Sury packages...
  • Loading branch information
HanXHX committed Feb 22, 2022
1 parent 28caf6d commit 4aef107
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
---

- 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'

- name: INCLUDE_VARS | Related to OS family
ansible.builtin.include_vars: "OS_Family_{{ ansible_os_family }}.yml"

Expand Down Expand Up @@ -64,6 +73,7 @@
state: present
update_cache: true
cache_valid_time: 3600
install_recommends: false
vars:
pkgs: "{{ php_packages + php_extra_packages | flatten }}"
notify: restart php-fpm
Expand Down
4 changes: 3 additions & 1 deletion tasks/opcache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

- name: APT | Install APCu
ansible.builtin.apt:
pkg: "php-apcu"
pkg: "{{ php_apcu_package }}"
install_recommends: false

- name: APT | Install Opcache
ansible.builtin.apt:
pkg: "{{ php_package_prefix }}opcache"
install_recommends: false

when: ansible_os_family == 'Debian'

Expand Down
1 change: 1 addition & 0 deletions tasks/xdebug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
state: present
update_cache: true
cache_valid_time: 3600
install_recommends: false
when: ansible_os_family == 'Debian'

- name: PKGNG | Install xdebug
Expand Down
18 changes: 18 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,21 @@
ansible.builtin.uri:
url: "http://localhost{{ php_fpm_poold.0.status_path }}"
when: php_fpm_poold.0.status_path is defined

- block:

- name: SHELL | Check if we installed multiple PHP versions
ansible.builtin.shell: set -o pipefail && (dpkg -l | grep 'php[[:digit:]].*common' | wc -l)
args:
executable: /bin/bash
failed_when: false
changed_when: false
register: check_multiple_php


- name: FAIL | If we have multiple PHP version
ansible.builtin.fail:
msg: "Multiple PHP versions detected"
when: check_multiple_php.stdout != '1'

when: ansible_os_family == 'Debian'
3 changes: 2 additions & 1 deletion vars/OS_Family_Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ php_packages:
- '{{ php_package_prefix }}mysql'
- '{{ php_package_prefix }}intl'

php_xdebug_package: 'php-xdebug'
php_xdebug_package: '{% if multiple_php.rc == 0 %}{{ php_package_prefix }}{% else %}php-{% endif %}xdebug'
php_apcu_package: '{% if multiple_php.rc == 0 %}{{ php_package_prefix }}{% else %}php-{% endif %}apcu'

php_package_prefix: 'php{{ php_version }}-'

Expand Down

0 comments on commit 4aef107

Please sign in to comment.