Use upstream config from HanXHX.php role

py3
Emilien Mantel 2019-12-26 17:16:13 +01:00
parent 993310641a
commit c524b97b0f
8 changed files with 77 additions and 8 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.swp
*.retry
*.pyc
/tests/HanXHX.php

View File

@ -26,6 +26,8 @@ before_install:
install:
- pip install "$ANSIBLE_VERSION"
- ansible-galaxy install -p ./tests HanXHX.php,master
- mv ./tests/HanXHX.php ./tests/TMP__HanXHX.php
script:
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM

View File

@ -105,6 +105,16 @@ Dependencies
None
If you need to dev this role locally
------------------------------------
Before use vagrant, run once:
```
ansible-galaxy install -p ./tests/ HanXHX.php,master && mv tests/HanXHX.php/ tests/TMP__HanXHX.php
```
Example Playbook
----------------

View File

@ -51,3 +51,4 @@
creates: "{{ nginx_acmesh_dir }}"
when: not acme.stat.exists

View File

@ -1,18 +1,40 @@
---
- 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"
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
when: nginx_php | length > 0
notify: reload nginx
- name: FILE | Delete PHP upstream
file:
path: "{{ nginx_etc_dir }}/conf.d/php.conf"
state: absent
when: nginx_php | length == 0
- name: TEMPLATE | Deploy other upstreams
template:
src: "etc/nginx/conf.d/_upstream.conf.j2"

View File

@ -14,7 +14,18 @@ upstream {{ php.upstream_name | default((php.version | php_default_upstream_name
server unix:{{ php.version | php_default_upstream_socket }} weight=1;
{% endfor %}
}
{% endfor %}
{% if ansible_local.hanxhx_php.fpm_pool is defined%}
# -------------------------------------------------------
# Auto-detected PHP config for HanXHX.php ansible role
# -------------------------------------------------------
{% for php in ansible_local.hanxhx_php.fpm_pool %}
upstream {{ php.name }} {
server {% if php.listen.startswith('/') %}unix:{{ php.listen }}{% else %}{{ php.listen }}{% endif %};
}
{% endfor %}
{% endif %}
# vim:filetype=nginx

View File

@ -78,3 +78,23 @@
- name: SET_FACT | ngrok_path
set_fact:
ngrok_path: '/tmp/ngrok'
- name: USER | Create PHP User foo
user:
name: foo
system: yes
- name: INCLUDE_ROLE | HanXHX.php
include_role:
name: "{{ playbook_dir }}/HanXHX.php"
vars:
php_autoremove_default_pool: false
php_fpm_poold:
- name: 'hx_unix'
user: 'foo'
php_value:
display_errors: 'Off'
php_admin_value:
memory_limit: '98M'
- name: 'hx_ip'
listen: '127.0.0.1:9636'

View File

@ -213,8 +213,10 @@
use_access_log: true
- name: 'test-php-index.local'
template: '_php_index'
php_upstream: 'hx_unix'
- name: 'test-php-index2.local'
template: '_php_index2'
php_upstream: 'hx_ip'
- name: 'test-proxy.local'
listen:
- 8080