From 33f72ee8f24176408653f27b32b59117c2eb8f23 Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Tue, 13 Nov 2018 09:57:44 +0300 Subject: [PATCH 1/8] Allow to generate custom locations in load_balancer mode --- defaults/main.yml | 5 ++++- templates/http/default.conf.j2 | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index e558f81..ab13caa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -168,7 +168,10 @@ nginx_http_template: html_file_name: index.html http_demo_conf: false load_balancer: - proxy_pass: backend + locations: + backend: + location: / + proxy_pass: backend health_check_plus: false upstreams: upstream1: diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index 827ad9f..9634427 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -24,8 +24,9 @@ server { {% endif %} server_name {{ item.value.server_name }}; {% if item.value.load_balancer is defined %} - location / { - proxy_pass http://{{ item.value.load_balancer.proxy_pass }}; +{% for location in item.value.load_balancer.locations %} + 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 %} health_check; {% endif %} @@ -34,6 +35,8 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } + +{% endfor %} {% endif %} {% if item.value.web_server is defined %} location / { From 709e52eb0b9db6339e378c9657a241a35c339fed Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Wed, 14 Nov 2018 23:33:54 +0700 Subject: [PATCH 2/8] Allow to generate custom locations in web_server mode --- templates/http/default.conf.j2 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index 9634427..a7fe9f9 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -39,10 +39,12 @@ server { {% endfor %} {% endif %} {% if item.value.web_server is defined %} - location / { - root {{ item.value.web_server.html_file_location }}; - index {{ item.value.web_server.html_file_name }}; +{% for location in item.value.web_server.locations %} + location {{ item.value.web_server.locations[location].location }} { + 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 %} sub_filter_once off; sub_filter 'server_hostname' '$hostname'; From 87db5ea0b8324f7da38bf25cb5319a913df4eba0 Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Wed, 14 Nov 2018 23:50:12 +0700 Subject: [PATCH 3/8] Update default/main.yml by adding vars for generating custom locations in web_server mode --- defaults/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index ab13caa..1f715b4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -164,8 +164,11 @@ nginx_http_template: cert: ssl/default.crt key: ssl/default.key web_server: - html_file_location: /usr/share/nginx/html - html_file_name: index.html + locations: + default: + location: / + html_file_location: /usr/share/nginx/html + html_file_name: index.html http_demo_conf: false load_balancer: locations: From aa4fcd34bd49eccebadd2b83cc93f7709f56d106 Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Thu, 15 Nov 2018 01:18:38 +0700 Subject: [PATCH 4/8] Update in README.md --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/README.md b/README.md index 1c875cc..1df076e 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,73 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role to a - 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: + - nginxinc.nginx + vars: + nginx_http_template_enable: true + nginx_http_template: + 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. ```yaml From e13606c8dfe866de09d05f6c25f9c141a374631f Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Thu, 15 Nov 2018 01:48:51 +0700 Subject: [PATCH 5/8] Typo correction --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1df076e..95f0283 100644 --- a/README.md +++ b/README.md @@ -313,17 +313,23 @@ This is a sample playbook file for deploying the Ansible Galaxy NGINX role in a - hosts: localhost become: true roles: - - nginxinc.nginx + - ansible-role-nginx vars: nginx_http_template_enable: true nginx_http_template: - web_server: - locations: - default: - location: / - html_file_location: /usr/share/nginx/html - html_file_name: index.html - + 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. From 75cc3b630e3674794cc4d871f93c83900b099008 Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Fri, 16 Nov 2018 07:46:14 +0300 Subject: [PATCH 6/8] Update README.md by adding new introduced vars --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 512d235..509c57f 100644 --- a/README.md +++ b/README.md @@ -331,12 +331,18 @@ nginx_http_template: cert: ssl/default.crt key: ssl/default.key web_server: - html_file_location: /usr/share/nginx/html - html_file_name: index.html + locations: + default: + location: / + html_file_location: /usr/share/nginx/html + html_file_name: index.html http_demo_conf: false load_balancer: - proxy_pass: backend - health_check_plus: false + locations + location1: + location: / + proxy_pass: backend + health_check_plus: false upstreams: upstream1: name: backend From 19d19483d77c975825a169db68c6b074722c7171 Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Fri, 16 Nov 2018 08:39:01 +0300 Subject: [PATCH 7/8] Typo correction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 509c57f..0718f2f 100644 --- a/README.md +++ b/README.md @@ -338,7 +338,7 @@ nginx_http_template: html_file_name: index.html http_demo_conf: false load_balancer: - locations + locations: location1: location: / proxy_pass: backend From 164a6bda9858d9a7ee4ed65567be51d35a7613ef Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Mon, 19 Nov 2018 07:10:19 +0300 Subject: [PATCH 8/8] Update test nginx-template.yml --- tests/playbooks/nginx-template.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/playbooks/nginx-template.yml b/tests/playbooks/nginx-template.yml index 841f848..daaea92 100644 --- a/tests/playbooks/nginx-template.yml +++ b/tests/playbooks/nginx-template.yml @@ -15,6 +15,9 @@ server_name: localhost error_page: /usr/share/nginx/html web_server: - html_file_location: /usr/share/nginx/html - html_file_name: index.html + locations: + default: + location: / + html_file_location: /usr/share/nginx/html + html_file_name: index.html http_demo_conf: false