Drop PHP version support (useless) + fix some bugs

py3
Emilien Mantel 2019-12-29 16:29:18 +01:00
parent 2a612a55b9
commit a9a72dd25f
13 changed files with 40 additions and 105 deletions

View File

@ -1,11 +1,12 @@
env: env:
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.6,<2.7' - 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-buster' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch' ANSIBLE_VERSION='ansible>=2.7,<2.8' - 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-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: matrix:
fast_finish: true fast_finish: true

10
Vagrantfile vendored
View File

@ -6,9 +6,8 @@
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
vms_debian = [ vms_debian = [
{ :name => "debian-stretch", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.0"}] }}, { :name => "debian-stretch", :box => "debian/stretch64", :vars => {} },
{ :name => "debian-stretch-sury", :box => "debian/stretch64", :vars => { "nginx_php": [{"version": "7.1"}], "sury": true }}, { :name => "debian-buster", :box => "debian/buster64", :vars => {} }
{ :name => "debian-buster", :box => "debian/buster64", :vars => { "nginx_php": [{"version": "7.3"}] }}
] ]
vms_freebsd = [ vms_freebsd = [
@ -17,9 +16,8 @@ Vagrant.configure("2") do |config|
] ]
conts = [ conts = [
{ :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "nginx_php": [{"version": "7.0"}] }}, { :name => "docker-debian-stretch", :docker => "hanxhx/vagrant-ansible:debian9", :vars => {} },
{ :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 => {} },
{ :name => "docker-debian-buster", :docker => "hanxhx/vagrant-ansible:debian10", :vars => { "nginx_php": [{"version": "7.3"}] }},
] ]
config.vm.network "private_network", type: "dhcp" config.vm.network "private_network", type: "dhcp"

View File

@ -2,8 +2,7 @@ PHP
=== ===
`nginx_php`: `nginx_php`:
- `version`: (M) PHP version - `upstream_name` (M)
- `upstream_name` (O)
- `sockets`: (O) socket list - `sockets`: (O) socket list
If `sockets` is not provided, if uses local unix socket (based on PHP version). If `sockets` is not provided, if uses local unix socket (based on PHP version).
@ -16,8 +15,8 @@ Each socket have:
XOR XOR
- `host` - `host` (M)
- `port` - `port` (M)
- `weight` - `weight` (O)
- `max_fails` - `max_fails` (O)
- `fail_timeout` - `fail_timeout` (O)

View File

@ -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. - `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_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". - `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. - `http_proxy_protocol_port` (O) Enable proxy protocol on http port.
- `https_proxy_protocol_port` (O) Enable proxy protocol on https port. - `https_proxy_protocol_port` (O) Enable proxy protocol on https port.

View File

@ -1,19 +1,10 @@
def php_default_upstream_socket(php_version): def php_default_upstream_socket(php_version):
return '/run/php/php%s-fpm.sock' % 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): class FilterModule(object):
''' PHP module ''' ''' PHP module '''
def filters(self): def filters(self):
return { return {
'php_default_upstream_socket': php_default_upstream_socket, '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
} }

View File

@ -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 - name: TEMPLATE | Deploy PHP upstream to Nginx
template: template:
src: "etc/nginx/conf.d/php.conf.j2" src: "etc/nginx/conf.d/php.conf.j2"

View File

@ -3,15 +3,13 @@
# #
{% for php in nginx_php %} {% 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([]) %} {% for sock in php.sockets | default([]) %}
{% if sock.host is defined %} {% 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') }}; 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 %} {% 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 %} {% endif %}
{% else %}
server unix:{{ php.version | php_default_upstream_socket }} weight=1;
{% endfor %} {% endfor %}
} }
{% endfor %} {% endfor %}

View File

@ -1,16 +1,5 @@
{% extends "_base.j2" %} {% 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 %} {% block template_index %}
index {{ item.index | default('index.html index.htm index.php') }}; index {{ item.index | default('index.html index.htm index.php') }};
{% endblock %} {% endblock %}
@ -21,8 +10,7 @@
{% block template_upstream_location %} {% block template_upstream_location %}
location ~ \.php$ { location ~ \.php$ {
# {{ php_info }} fastcgi_pass {{ item.php_upstream }};
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php; fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %} {% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %} {% for param in item.upstream_params %}

View File

@ -2,8 +2,7 @@
{% block template_upstream_location %} {% block template_upstream_location %}
location = /index.php { location = /index.php {
# {{ php_info }} fastcgi_pass {{ item.php_upstream }};
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php; fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %} {% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %} {% for param in item.upstream_params %}

View File

@ -6,8 +6,7 @@
{% block template_upstream_location %} {% block template_upstream_location %}
location = /index.php { location = /index.php {
# {{ php_info }} fastcgi_pass {{ item.php_upstream }};
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php; fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %} {% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %} {% for param in item.upstream_params %}

View File

@ -10,8 +10,7 @@
} }
location ~ ^/index\.php(/|$) { location ~ ^/index\.php(/|$) {
# {{ php_info }} fastcgi_pass {{ item.php_upstream }};
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php; fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %} {% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %} {% for param in item.upstream_params %}

View File

@ -6,24 +6,6 @@
state: present state: present
when: nginx_backports 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 - name: APT | Install needed packages
apt: apt:
pkg: "{{ packages }}" pkg: "{{ packages }}"
@ -44,12 +26,19 @@
- name: APT | Install PHP - name: APT | Install PHP
apt: apt:
pkg: "{{ item.version | php_fpm_package }}" pkg: "{{ pkgs }}"
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
state: present state: present
loop: "{{ nginx_php }}" vars:
register: apt_php 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 - name: SERVICE | Force start fcgiwrap
service: service:
@ -58,11 +47,10 @@
# Bypasses Ansible+Docker issue. With service module... php is not really started! # Bypasses Ansible+Docker issue. With service module... php is not really started!
- name: COMMAND | Force start PHP - name: COMMAND | Force start PHP
command: "service {{ item.version | php_fpm_service }} start" command: "service php{{ cur_php_version.stdout }}-fpm start"
args: args:
creates: "{{ item.version | php_default_upstream_socket }}" creates: "/run/php/php{{ cur_php_version.stdout }}-fpm.pid"
warn: false warn: false
loop: "{{ nginx_php }}"
- name: GET_URL | Download ngrok - name: GET_URL | Download ngrok
get_url: get_url:
@ -88,7 +76,7 @@
include_role: include_role:
name: "{{ playbook_dir }}/HanXHX.php" name: "{{ playbook_dir }}/HanXHX.php"
vars: vars:
php_version: "{{ nginx_php.0.version }}" php_version: "{{ cur_php_version.stdout }}"
php_autoremove_default_pool: false php_autoremove_default_pool: false
php_fpm_poold: php_fpm_poold:
- name: 'hx_unix' - name: 'hx_unix'

View File

@ -2,6 +2,7 @@
- hosts: all - hosts: all
pre_tasks: pre_tasks:
- name: INCLUDE_TASKS | Pre_tasks related to OS version - name: INCLUDE_TASKS | Pre_tasks related to OS version
include_tasks: "includes/pre_{{ ansible_distribution }}.yml" include_tasks: "includes/pre_{{ ansible_distribution }}.yml"
@ -23,6 +24,7 @@
src: "file/test.key" src: "file/test.key"
dest: "{{ int_ansible_ssl_dir }}/test.key" dest: "{{ int_ansible_ssl_dir }}/test.key"
- debug: var=nginx_sites
- name: COPY | Add all hosts in /etc/hosts - name: COPY | Add all hosts in /etc/hosts
copy: copy:
content: | content: |
@ -203,7 +205,7 @@
- '/' - '/'
- '/a' - '/a'
- name: 'test-php.local' - 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: upstream_params:
- 'fastcgi_param FOO bar;' - 'fastcgi_param FOO bar;'
redirect_from: redirect_from:
@ -274,6 +276,9 @@
ssl_name: '{{ ngrok.stdout }}' ssl_name: '{{ ngrok.stdout }}'
headers: headers:
'X-acme': '1' '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 nginx_dh_length: 1024
roles: roles:
- ../../ - ../../
@ -374,7 +379,7 @@
when: > when: >
item.template is defined and item.template is defined and
(item.template == '_php' or item.template == '_php_index' or item.template == '_php_index2') (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 -- - name: -- VERIFY INDEX2 --
uri: uri: