ansible-nginx/tasks/upstream.yml

53 lines
1.4 KiB
YAML
Raw Permalink Normal View History

2015-07-15 21:26:27 +07:00
---
- 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
2015-07-15 21:26:27 +07:00
- name: TEMPLATE | Deploy PHP upstream to Nginx
2017-07-27 17:21:10 +07:00
template:
2017-10-26 16:09:21 +07:00
src: "etc/nginx/conf.d/php.conf.j2"
2017-07-27 17:21:10 +07:00
dest: "{{ nginx_etc_dir }}/conf.d/php.conf"
2015-07-15 21:26:27 +07:00
notify: reload nginx
2015-10-08 23:21:40 +07:00
- name: TEMPLATE | Deploy other upstreams
2017-07-27 17:21:10 +07:00
template:
2017-10-26 16:09:21 +07:00
src: "etc/nginx/conf.d/_upstream.conf.j2"
2017-07-27 17:21:10 +07:00
dest: "{{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf"
loop: "{{ nginx_upstreams }}"
when: item.state is not defined or item.state == 'present'
notify: reload nginx
- name: FILE | Delete other upstreams
2017-07-27 17:21:10 +07:00
file:
path: "{{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf"
state: absent
2019-02-05 03:25:25 +07:00
loop: "{{ nginx_upstreams }}"
when: item.state is defined and item.state == 'absent'
2015-10-08 23:21:40 +07:00
notify: reload nginx