diff --git a/.gitignore b/.gitignore index 5a00188..b44e1d2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.swp *.retry *.pyc +/tests/HanXHX.php diff --git a/.travis.yml b/.travis.yml index 33b6c18..ba543a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index a687faa..62c80b2 100644 --- a/README.md +++ b/README.md @@ -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 ---------------- diff --git a/tasks/install_Debian.yml b/tasks/install_Debian.yml index 96bb246..c421d73 100644 --- a/tasks/install_Debian.yml +++ b/tasks/install_Debian.yml @@ -51,3 +51,4 @@ creates: "{{ nginx_acmesh_dir }}" when: not acme.stat.exists + diff --git a/tasks/upstream.yml b/tasks/upstream.yml index 56c920c..4204ff2 100644 --- a/tasks/upstream.yml +++ b/tasks/upstream.yml @@ -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" diff --git a/templates/etc/nginx/conf.d/php.conf.j2 b/templates/etc/nginx/conf.d/php.conf.j2 index b0273a6..11cc6fc 100644 --- a/templates/etc/nginx/conf.d/php.conf.j2 +++ b/templates/etc/nginx/conf.d/php.conf.j2 @@ -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 diff --git a/tests/includes/pre_Debian.yml b/tests/includes/pre_Debian.yml index 5d5ea5b..755bdf7 100644 --- a/tests/includes/pre_Debian.yml +++ b/tests/includes/pre_Debian.yml @@ -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' diff --git a/tests/test.yml b/tests/test.yml index 5ae3363..af044e2 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -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