Merge pull request #72 from 0x28d/master

Allow to generate custom locations in load_balancer mode
This commit is contained in:
Alessandro Fael Garcia 2018-11-19 10:26:44 -08:00 committed by GitHub
commit 39dd5a29cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 14 deletions

View File

@ -331,12 +331,18 @@ nginx_http_template:
cert: ssl/default.crt cert: ssl/default.crt
key: ssl/default.key key: ssl/default.key
web_server: web_server:
html_file_location: /usr/share/nginx/html locations:
html_file_name: index.html default:
location: /
html_file_location: /usr/share/nginx/html
html_file_name: index.html
http_demo_conf: false http_demo_conf: false
load_balancer: load_balancer:
proxy_pass: backend locations:
health_check_plus: false location1:
location: /
proxy_pass: backend
health_check_plus: false
upstreams: upstreams:
upstream1: upstream1:
name: backend name: backend
@ -384,6 +390,79 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a
- role: nginxinc.nginx - role: nginxinc.nginx
``` ```
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing the open source version of NGINX as a simple web server.
```yaml
---
- hosts: localhost
become: true
roles:
- ansible-role-nginx
vars:
nginx_http_template_enable: true
nginx_http_template:
default:
template_file: http/default.conf.j2
conf_file_name: default.conf
conf_file_location: /etc/nginx/conf.d/
port: 80
server_name: localhost
error_page: /usr/share/nginx/html
web_server:
locations:
default:
location: /
html_file_location: /usr/share/nginx/html
html_file_name: index.html
```
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing the open source version of NGINX as a reverse proxy.
```yaml
---
- hosts: localhost
become: true
roles:
- nginxinc.nginx
vars:
nginx_http_template_enable: true
nginx_http_template:
load_balancer:
locations:
frontend:
location: /
proxy_pass: frontend_servers
backend:
location: /backend
proxy_pass: backend_servers
upstreams:
upstream_1:
name: frontend_servers
lb_method: least_conn
zone_name: frontend
zone_size: 64k
sticky_cookie: false
servers:
frontend_server_1:
address: localhost
port: 80
weight: 1
health_check: max_fails=3 fail_timeout=5s
upstream_2:
name: backend_servers
lb_method: least_conn
zone_name: backend
zone_size: 64k
sticky_cookie: false
servers:
backend_server_1:
address: localhost
port: 8080
weight: 1
health_check: max_fails=3 fail_timeout=5s
```
This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing NGINX Plus. This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a localhost and installing NGINX Plus.
```yaml ```yaml

View File

@ -164,11 +164,17 @@ nginx_http_template:
cert: ssl/default.crt cert: ssl/default.crt
key: ssl/default.key key: ssl/default.key
web_server: web_server:
html_file_location: /usr/share/nginx/html locations:
html_file_name: index.html default:
location: /
html_file_location: /usr/share/nginx/html
html_file_name: index.html
http_demo_conf: false http_demo_conf: false
load_balancer: load_balancer:
proxy_pass: backend locations:
backend:
location: /
proxy_pass: backend
health_check_plus: false health_check_plus: false
upstreams: upstreams:
upstream1: upstream1:

View File

@ -24,8 +24,9 @@ server {
{% endif %} {% endif %}
server_name {{ item.value.server_name }}; server_name {{ item.value.server_name }};
{% if item.value.load_balancer is defined %} {% if item.value.load_balancer is defined %}
location / { {% for location in item.value.load_balancer.locations %}
proxy_pass http://{{ item.value.load_balancer.proxy_pass }}; location {{ item.value.load_balancer.locations[location].location }} {
proxy_pass http://{{ item.value.load_balancer.locations[location].proxy_pass }};
{% if item.value.load_balancer.health_check_plus %} {% if item.value.load_balancer.health_check_plus %}
health_check; health_check;
{% endif %} {% endif %}
@ -34,12 +35,16 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
{% endfor %}
{% endif %} {% endif %}
{% if item.value.web_server is defined %} {% if item.value.web_server is defined %}
location / { {% for location in item.value.web_server.locations %}
root {{ item.value.web_server.html_file_location }}; location {{ item.value.web_server.locations[location].location }} {
index {{ item.value.web_server.html_file_name }}; root {{ item.value.web_server.locations[location].html_file_location }};
index {{ item.value.web_server.locations[location].html_file_name }};
} }
{% endfor %}
{% if item.value.web_server.http_demo_conf %} {% if item.value.web_server.http_demo_conf %}
sub_filter_once off; sub_filter_once off;
sub_filter 'server_hostname' '$hostname'; sub_filter 'server_hostname' '$hostname';

View File

@ -15,6 +15,9 @@
server_name: localhost server_name: localhost
error_page: /usr/share/nginx/html error_page: /usr/share/nginx/html
web_server: web_server:
html_file_location: /usr/share/nginx/html locations:
html_file_name: index.html default:
location: /
html_file_location: /usr/share/nginx/html
html_file_name: index.html
http_demo_conf: false http_demo_conf: false