From a9a72dd25f00880df9547919058f902becf2e068 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sun, 29 Dec 2019 16:29:18 +0100 Subject: [PATCH] Drop PHP version support (useless) + fix some bugs --- .travis.yml | 7 ++-- Vagrantfile | 10 ++--- doc/php.md | 13 +++---- doc/site.md | 1 - filter_plugins/php.py | 9 ----- tasks/upstream.yml | 29 -------------- templates/etc/nginx/conf.d/php.conf.j2 | 6 +-- templates/etc/nginx/sites-available/_php.j2 | 14 +------ .../etc/nginx/sites-available/_php_index.j2 | 3 +- .../etc/nginx/sites-available/_php_index2.j2 | 3 +- .../etc/nginx/sites-available/_symfony.j2 | 3 +- tests/includes/pre_Debian.yml | 38 +++++++------------ tests/test.yml | 9 ++++- 13 files changed, 40 insertions(+), 105 deletions(-) diff --git a/.travis.yml b/.travis.yml index b44b9d2..5ce1287 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,12 @@ env: - PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.6,<2.7' - - PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.6,<2.7' - PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.6,<2.7' - PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.7,<2.8' - - PLATFORM='docker-debian-stretch-sury' ANSIBLE_VERSION='ansible>=2.7,<2.8' - PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.7,<2.8' - + - PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.8,<2.9' + - PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.8,<2.9' + - PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.9,<2.10' + - PLATFORM='docker-debian-buster' ANSIBLE_VERSION='ansible>=2.9,<2.10' matrix: fast_finish: true diff --git a/Vagrantfile b/Vagrantfile index 8469fae..0408a90 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,9 +6,8 @@ Vagrant.configure("2") do |config| vms_debian = [ - { :name => "debian-stretch", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.0"}] }}, - { :name => "debian-stretch-sury", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}, - { :name => "debian-buster", :box => "debian/buster64", :vars => { "nginx_php": [{"version": "7.3"}] }} + { :name => "debian-stretch", :box => "debian/stretch64", :vars => {} }, + { :name => "debian-buster", :box => "debian/buster64", :vars => {} } ] vms_freebsd = [ @@ -17,9 +16,8 @@ Vagrant.configure("2") do |config| ] conts = [ - { :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.0"}] }}, - { :name => "docker-debian-stretch-sury", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}, - { :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => { "nginx_php": [{"version": "7.3"}] }}, + { :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => {} }, + { :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => {} }, ] config.vm.network "private_network", type: "dhcp" diff --git a/doc/php.md b/doc/php.md index 6d7cafc..62b471e 100644 --- a/doc/php.md +++ b/doc/php.md @@ -2,8 +2,7 @@ PHP === `nginx_php`: - - `version`: (M) PHP version - - `upstream_name` (O) + - `upstream_name` (M) - `sockets`: (O) socket list If `sockets` is not provided, if uses local unix socket (based on PHP version). @@ -16,8 +15,8 @@ Each socket have: XOR -- `host` -- `port` -- `weight` -- `max_fails` -- `fail_timeout` +- `host` (M) +- `port` (M) +- `weight` (O) +- `max_fails` (O) +- `fail_timeout` (O) diff --git a/doc/site.md b/doc/site.md index bc46507..4a6b43c 100644 --- a/doc/site.md +++ b/doc/site.md @@ -29,7 +29,6 @@ Common - `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support. - `ssl_name`: (D) name of the key used when using TLS/SSL. Optional when `proto` contains "https". If you don't set this value, it will search by `name`. - `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false". -- `php_version` (O) Sepecify PHP version (5 or 7) - `http_proxy_protocol_port` (O) Enable proxy protocol on http port. - `https_proxy_protocol_port` (O) Enable proxy protocol on https port. diff --git a/filter_plugins/php.py b/filter_plugins/php.py index 23c5a23..db5f4f4 100644 --- a/filter_plugins/php.py +++ b/filter_plugins/php.py @@ -1,19 +1,10 @@ def php_default_upstream_socket(php_version): return '/run/php/php%s-fpm.sock' % php_version -def php_default_upstream_name(php_version): - return 'default_php_%s' % php_version - -def php_fpm_service(php_version): - return 'php%s-fpm' % php_version - class FilterModule(object): ''' PHP module ''' def filters(self): return { 'php_default_upstream_socket': php_default_upstream_socket, - 'php_default_upstream_name': php_default_upstream_name, - 'php_fpm_service': php_fpm_service, - 'php_fpm_package': php_fpm_service } diff --git a/tasks/upstream.yml b/tasks/upstream.yml index 4204ff2..fe57bb6 100644 --- a/tasks/upstream.yml +++ b/tasks/upstream.yml @@ -1,34 +1,5 @@ --- -- block: - - - name: SET_FACT | temp - set_fact: - tmp_fpm_pool: | - [ - {% for p in ansible_local.hanxhx_php.fpm_pool %} - { - "upstream_name": "{{ p.name }}", - "sockets": [{ - {% if p.listen.startswith('/') %} - "unix": "{{ p.listen }}" - {% else %} - {% set host = p.listen.split(":")[0] %} - {% set port = p.listen.split(":")[1] %} - "host": "{{ host }}", - "port": "{{ port }}" - {% endif %} - }] - }{% if not loop.last %},{% endif %} - {% endfor %} - ] - - - name: SET_FACT | new php - set_fact: - nginx_php: "{{ nginx_php + tmp_fpm_pool }}" - - when: ansible_local.hanxhx_php.fpm_pool is defined - - name: TEMPLATE | Deploy PHP upstream to Nginx template: src: "etc/nginx/conf.d/php.conf.j2" diff --git a/templates/etc/nginx/conf.d/php.conf.j2 b/templates/etc/nginx/conf.d/php.conf.j2 index 11cc6fc..0052719 100644 --- a/templates/etc/nginx/conf.d/php.conf.j2 +++ b/templates/etc/nginx/conf.d/php.conf.j2 @@ -3,15 +3,13 @@ # {% for php in nginx_php %} -upstream {{ php.upstream_name | default((php.version | php_default_upstream_name)) }} { +upstream {{ php.upstream_name }} { {% for sock in php.sockets | default([]) %} {% if sock.host is defined %} server {{ sock.host }}:{{ sock.port }} weight={{ sock.weight | default('1') }} max_fails={{ sock.max_fails | default('5') }} fail_timeout={{ sock.fail_timeout | default('10s') }}; {% else %} - server unix:{{ sock.unix | default((php.version | php_default_upstream_socket)) }} weight={{ sock.weight | default('1') }}; + server unix:{{ sock.unix }} weight={{ sock.weight | default('1') }}; {% endif %} -{% else %} - server unix:{{ php.version | php_default_upstream_socket }} weight=1; {% endfor %} } {% endfor %} diff --git a/templates/etc/nginx/sites-available/_php.j2 b/templates/etc/nginx/sites-available/_php.j2 index ff5143b..1d88fdf 100644 --- a/templates/etc/nginx/sites-available/_php.j2 +++ b/templates/etc/nginx/sites-available/_php.j2 @@ -1,16 +1,5 @@ {% extends "_base.j2" %} -{% if item.php_version is defined %} -{% set php_info = 'Explicit PHP version on site' %} -{% set php_upstream = (nginx_php|selectattr('version', 'equalto', item.php_version)|first).upstream_name | default(item.php_version | php_default_upstream_name) %} -{% elif item.php_upstream is defined %} -{% set php_info = 'Explicit Nginx/PHP upstream on site' %} -{% set php_upstream = item.php_upstream %} -{% else %} -{% set php_info = 'Warning: using first PHP version on config' %} -{% set php_upstream = nginx_php.0.upstream_name | default(nginx_php.0.version | php_default_upstream_name) %} -{% endif %} - {% block template_index %} index {{ item.index | default('index.html index.htm index.php') }}; {% endblock %} @@ -21,8 +10,7 @@ {% block template_upstream_location %} location ~ \.php$ { - # {{ php_info }} - fastcgi_pass {{ php_upstream }}; + fastcgi_pass {{ item.php_upstream }}; fastcgi_index index.php; {% if item.upstream_params is defined and item.upstream_params is iterable %} {% for param in item.upstream_params %} diff --git a/templates/etc/nginx/sites-available/_php_index.j2 b/templates/etc/nginx/sites-available/_php_index.j2 index e4a45c3..0e953a4 100644 --- a/templates/etc/nginx/sites-available/_php_index.j2 +++ b/templates/etc/nginx/sites-available/_php_index.j2 @@ -2,8 +2,7 @@ {% block template_upstream_location %} location = /index.php { - # {{ php_info }} - fastcgi_pass {{ php_upstream }}; + fastcgi_pass {{ item.php_upstream }}; fastcgi_index index.php; {% if item.upstream_params is defined and item.upstream_params is iterable %} {% for param in item.upstream_params %} diff --git a/templates/etc/nginx/sites-available/_php_index2.j2 b/templates/etc/nginx/sites-available/_php_index2.j2 index 0d34dd1..14891ba 100644 --- a/templates/etc/nginx/sites-available/_php_index2.j2 +++ b/templates/etc/nginx/sites-available/_php_index2.j2 @@ -6,8 +6,7 @@ {% block template_upstream_location %} location = /index.php { - # {{ php_info }} - fastcgi_pass {{ php_upstream }}; + fastcgi_pass {{ item.php_upstream }}; fastcgi_index index.php; {% if item.upstream_params is defined and item.upstream_params is iterable %} {% for param in item.upstream_params %} diff --git a/templates/etc/nginx/sites-available/_symfony.j2 b/templates/etc/nginx/sites-available/_symfony.j2 index 8cab2fa..245fa41 100644 --- a/templates/etc/nginx/sites-available/_symfony.j2 +++ b/templates/etc/nginx/sites-available/_symfony.j2 @@ -10,8 +10,7 @@ } location ~ ^/index\.php(/|$) { - # {{ php_info }} - fastcgi_pass {{ php_upstream }}; + fastcgi_pass {{ item.php_upstream }}; fastcgi_index index.php; {% if item.upstream_params is defined and item.upstream_params is iterable %} {% for param in item.upstream_params %} diff --git a/tests/includes/pre_Debian.yml b/tests/includes/pre_Debian.yml index ad3bf3c..967e2b7 100644 --- a/tests/includes/pre_Debian.yml +++ b/tests/includes/pre_Debian.yml @@ -6,24 +6,6 @@ state: present when: nginx_backports -- block: - - - name: APT | Install apt-transport-https - apt: - pkg: apt-transport-https - update_cache: yes - cache_valid_time: 3600 - - - name: APT_KEY | Install GPG key - apt_key: - url: 'https://packages.sury.org/php/apt.gpg' - - - name: APT_REPOSITORY | Add APT repository - apt_repository: - repo: 'deb https://packages.sury.org/php {{ ansible_distribution_release }} main' - - when: sury | default(false) - - name: APT | Install needed packages apt: pkg: "{{ packages }}" @@ -44,12 +26,19 @@ - name: APT | Install PHP apt: - pkg: "{{ item.version | php_fpm_package }}" + pkg: "{{ pkgs }}" update_cache: yes cache_valid_time: 3600 state: present - loop: "{{ nginx_php }}" - register: apt_php + vars: + pkgs: + - php-cli + - php-fpm + +- name: SHELL | Get current PHP version + shell: php --version | awk '/^PHP/ { print $2 }' | grep -o -E '^.{3}' + changed_when: false + register: cur_php_version - name: SERVICE | Force start fcgiwrap service: @@ -58,11 +47,10 @@ # Bypasses Ansible+Docker issue. With service module... php is not really started! - name: COMMAND | Force start PHP - command: "service {{ item.version | php_fpm_service }} start" + command: "service php{{ cur_php_version.stdout }}-fpm start" args: - creates: "{{ item.version | php_default_upstream_socket }}" + creates: "/run/php/php{{ cur_php_version.stdout }}-fpm.pid" warn: false - loop: "{{ nginx_php }}" - name: GET_URL | Download ngrok get_url: @@ -88,7 +76,7 @@ include_role: name: "{{ playbook_dir }}/HanXHX.php" vars: - php_version: "{{ nginx_php.0.version }}" + php_version: "{{ cur_php_version.stdout }}" php_autoremove_default_pool: false php_fpm_poold: - name: 'hx_unix' diff --git a/tests/test.yml b/tests/test.yml index af044e2..6b19ded 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -2,6 +2,7 @@ - hosts: all pre_tasks: + - name: INCLUDE_TASKS | Pre_tasks related to OS version include_tasks: "includes/pre_{{ ansible_distribution }}.yml" @@ -23,6 +24,7 @@ src: "file/test.key" dest: "{{ int_ansible_ssl_dir }}/test.key" + - debug: var=nginx_sites - name: COPY | Add all hosts in /etc/hosts copy: content: | @@ -203,7 +205,7 @@ - '/' - '/a' - name: 'test-php.local' - php_version: "{{ nginx_php.1.version if nginx_php.1 is defined else nginx_php.0.version }}" + php_upstream: "manual" upstream_params: - 'fastcgi_param FOO bar;' redirect_from: @@ -274,6 +276,9 @@ ssl_name: '{{ ngrok.stdout }}' headers: 'X-acme': '1' + + #nginx_php: "{{ __nginx_php + [{'upstream_name': 'manual', 'sockets': [{'host': '127.0.0.1', 'port': '9636' }] }] }}" + nginx_php: "{{ [{'upstream_name': 'manual', 'sockets': [{'host': '127.0.0.1', 'port': '9636' }] }] }}" nginx_dh_length: 1024 roles: - ../../ @@ -374,7 +379,7 @@ when: > item.template is defined and (item.template == '_php' or item.template == '_php_index' or item.template == '_php_index2') - failed_when: p.content.find('PHP Version ' + item.php_version if 'php_version' in item else nginx_php.0.version) == -1 + failed_when: p.content.find('PHP Version') == -1 - name: -- VERIFY INDEX2 -- uri: