Skip to content

Commit

Permalink
Improve PHP version detection on Debian-based systems
Browse files Browse the repository at this point in the history
  • Loading branch information
medanthelinium committed Feb 7, 2024
1 parent bd274e7 commit f6741f3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ skip_list:
- 'role-name'

warn_list:
- jinja[spacing]
- package-latest
- unnamed-task
- command-instead-of-shell
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
php_version:
# Undefined by default, is populated during the run
php:
prefix:
config: >-
Expand Down
12 changes: 0 additions & 12 deletions tasks/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,3 @@
map('regex_replace', '^', 'php-') |
list + (['composer'] if php.install_composer else [])
}}
- name: Get PHP version
changed_when: no
register: php_version_full
check_mode: no
ansible.builtin.shell:
cmd: >-
php -r 'echo phpversion();' | grep -o '[0-9]\.[0-9]' | head -n1
- name: Set PHP version fact
ansible.builtin.set_fact:
php_version: "{{ php_version_full.stdout }}"
11 changes: 7 additions & 4 deletions tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
- name: Set the PHP version
ansible.builtin.include_tasks: phpversion.yaml

- name: Install PHP and extensions (Ubuntu/Debian)
when: ansible_os_family == 'Debian'
ansible.builtin.import_tasks: install.yaml
ansible.builtin.include_tasks: install.yaml

- name: Set up phpfpmtop
ansible.builtin.import_tasks: phpfpmtop.yaml
ansible.builtin.include_tasks: phpfpmtop.yaml

- name: Configure PHP-FPM
ansible.builtin.import_tasks: phpfpm.yaml
ansible.builtin.include_tasks: phpfpm.yaml

- name: Configure PHP
ansible.builtin.import_tasks: php.yaml
ansible.builtin.include_tasks: php.yaml
20 changes: 20 additions & 0 deletions tasks/phpversion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Get PHP version
changed_when: no
register: php_version_full
check_mode: no
ansible.builtin.shell:
cmd: >-

Check warning on line 7 in tasks/phpversion.yaml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: {%- if ansible_os_family == 'Debian' -%} apt update && apt-cache search --names-only "^php[0-9].[0-9]$" | awk '{print $1}' {%- elif ansible_os_family == 'FreeBSD' -%} # PHP is already installed on the Proserver hosts, no need to query the packages php -r 'echo phpversion();' | grep -o '[0-9]\.[0-9]' | head -n1 {%- else -%} echo "Unsupported OS" && exit 1 {%- endif -%} -> {%- if ansible_os_family == 'Debian' -%} apt update && apt-cache search --names-only "^php[0-9].[0-9]$" | awk '{print $1}'{%- elif ansible_os_family == 'FreeBSD' -%} # PHP is already installed on the Proserver hosts, no need to query the packages php -r 'echo phpversion();' | grep -o '[0-9]\.[0-9]' | head -n1{%- else -%} echo "Unsupported OS" && exit 1{%- endif -%}
{%- if ansible_os_family == 'Debian' -%}
apt update &&
apt-cache search --names-only "^php[0-9].[0-9]$" | awk '{print $1}'
{%- elif ansible_os_family == 'FreeBSD' -%}
# PHP is already installed on the Proserver hosts, no need to query the packages
php -r 'echo phpversion();' | grep -o '[0-9]\.[0-9]' | head -n1
{%- else -%}
echo "Unsupported OS" && exit 1
{%- endif -%}
- name: Set PHP version fact
ansible.builtin.set_fact:
php_version: "{{ php_version_full.stdout }}"

0 comments on commit f6741f3

Please sign in to comment.