diff --git a/tasks/main.yml b/tasks/main.yml index 45cc97c..a3619e3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -23,8 +23,8 @@ with_fileglob: '../templates/etc/nginx/helpers/*.j2' notify: reload nginx -- name: INCLUDE | PHP configuration - include: php.yml +- name: INCLUDE | Upstream configuration + include: upstream.yml when: nginx_php - name: INCLUDE | Vhosts configuration diff --git a/tasks/php.yml b/tasks/php.yml deleted file mode 100644 index 4bc91fe..0000000 --- a/tasks/php.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- - -- name: INCLUDE_VARS | Include PHP defaults vars from PHP role if unspecified - include_vars: ../../php/defaults/main.yml - when: php_fpm_socket is undefined - -- name: TEMPLATE | Deploy PHP upstream (UNIX sockets) to Nginx - template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf - notify: reload nginx - diff --git a/tasks/upstream.yml b/tasks/upstream.yml new file mode 100644 index 0000000..7f9d9cf --- /dev/null +++ b/tasks/upstream.yml @@ -0,0 +1,6 @@ +--- + +- name: TEMPLATE | Deploy PHP upstream to Nginx + template: src=etc/nginx/upstream/php.conf.j2 dest=/etc/nginx/conf.d/php.conf + notify: reload nginx + diff --git a/templates/etc/nginx/upstream/php.conf.j2 b/templates/etc/nginx/upstream/php.conf.j2 index 7f7a85c..e8034d2 100644 --- a/templates/etc/nginx/upstream/php.conf.j2 +++ b/templates/etc/nginx/upstream/php.conf.j2 @@ -1,26 +1,22 @@ # # {{ ansible_managed }} # - -{% if nginx_php_method == 'unix' %} -upstream php { - {% for item in php_fpm_unix_sockets %} - server unix:{{ item }}; - {% endfor %} -} -{% elif nginx_php_method == 'tcp' %} +{% if nginx_php_method == 'tcp' %} upstream php { {% if nginx_cluster_php_method is defined %} {{ nginx_cluster_php_method }}; {% endif %} - {% for item in nginx_cluster_servers %} + {% for item in nginx_php_tcp_sockets %} server {{ item.host }}:{{ item.port }} weight={{ item.weight | default('100') }} max_fails={{ item.max_fails | default('5') }} fail_timeout={{ item.fail_timeout | default('10s') }}; {% endfor %} } +{% elif nginx_php_method == 'unix' %} +upstream php { + {% for item in nginx_php_unix_sockets %} + server unix:{{ item }}; + {% endfor %} +} {% else %} -# -# Bad configuration... -# -{% endif%} +{% endif %} # vim:filetype=nginx diff --git a/templates/etc/nginx/upstream/php_tcp.j2 b/templates/etc/nginx/upstream/php_tcp.j2 deleted file mode 100644 index c31ab21..0000000 --- a/templates/etc/nginx/upstream/php_tcp.j2 +++ /dev/null @@ -1,14 +0,0 @@ -# -# {{ ansible_managed }} -# - -upstream php { - {% if nginx_cluster_php_method is defined %} - {{ nginx_cluster_php_method }}; - {% endif %} - {% for item in nginx_cluster_servers %} - server {{ item.host }}:{{ item.port }} weight={{ item.weight | default('100') }} max_fails={{ item.max_fails | default('5') }} fail_timeout={{ item.fail_timeout | default('10s') }}; - {% endfor %} -} - -# vim:filetype=nginx diff --git a/tests/test.yml b/tests/test.yml index 82ef063..8d7984e 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,13 +1,18 @@ --- - hosts: all + pre_tasks: + - apt: pkg=php5-fpm update_cache=yes cache_valid_time=3600 state=present vars: + nginx_php: true nginx_vhosts: - name: 'test.local' template: 'static' ssl: use: false - generatekey: false - template: 'strong' + - name: 'test-php.local' + template: 'wordpress' + ssl: + use: false roles: - ../../