mirror of
https://github.com/HanXHX/ansible-nginx.git
synced 2026-03-10 10:12:09 +07:00
New feature: upstream state (remove upstream if needed)
This commit is contained in:
@@ -11,6 +11,7 @@ Upstream params
|
|||||||
- `name`: upstream name. Can be use in vhost with *proxy_pass http://upstream_name*
|
- `name`: upstream name. Can be use in vhost with *proxy_pass http://upstream_name*
|
||||||
- `params`: list of param (hash, zone...)
|
- `params`: list of param (hash, zone...)
|
||||||
- `servers`: each upstream MUST have at least 1 server
|
- `servers`: each upstream MUST have at least 1 server
|
||||||
|
- `state`: Optional. Can be 'absent' or 'present'
|
||||||
|
|
||||||
Server params
|
Server params
|
||||||
-------------
|
-------------
|
||||||
@@ -38,4 +39,5 @@ nginx_upstreams:
|
|||||||
max_conns: 150
|
max_conns: 150
|
||||||
weight: 10
|
weight: 10
|
||||||
down: false
|
down: false
|
||||||
|
state: 'present'
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,4 +12,13 @@
|
|||||||
src=etc/nginx/upstream/upstream.conf.j2
|
src=etc/nginx/upstream/upstream.conf.j2
|
||||||
dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
|
dest={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
|
||||||
with_items: "{{ nginx_upstreams }}"
|
with_items: "{{ nginx_upstreams }}"
|
||||||
|
when: item.state is not defined or item.state == 'present'
|
||||||
|
notify: reload nginx
|
||||||
|
|
||||||
|
- name: FILE | Delete other upstreams
|
||||||
|
file: >
|
||||||
|
path={{ nginx_etc_dir }}/conf.d/upstream-{{ item.name }}.conf
|
||||||
|
state=absent
|
||||||
|
with_items: "{{ nginx_upstreams }}"
|
||||||
|
when: item.state is defined and item.state == 'absent'
|
||||||
notify: reload nginx
|
notify: reload nginx
|
||||||
|
|||||||
@@ -24,6 +24,13 @@
|
|||||||
max_conns: 150
|
max_conns: 150
|
||||||
weight: 10
|
weight: 10
|
||||||
down: false
|
down: false
|
||||||
|
- name: 'test-absent'
|
||||||
|
servers:
|
||||||
|
- path: '127.0.0.1:80'
|
||||||
|
max_conns: 150
|
||||||
|
weight: 10
|
||||||
|
down: false
|
||||||
|
state: 'absent'
|
||||||
nginx_htpasswd:
|
nginx_htpasswd:
|
||||||
- name: 'hello'
|
- name: 'hello'
|
||||||
description: 'Please login!'
|
description: 'Please login!'
|
||||||
|
|||||||
Reference in New Issue
Block a user