From 5a1a3e6ef16f72cdab2f4d969c1f3467726b4881 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 20 Jan 2020 14:37:38 +0100 Subject: [PATCH] allow multiple upstream groups from list --- defaults/main.yml | 6 +++--- templates/etc/nginx/sites-available/vhost.j2 | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 90480d3..7e2fc8b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -103,9 +103,9 @@ nginx_vhosts_default: # @var nginx_vhosts_default:example: > # nginx_vhosts_default: # - file: default -# upstream: -# name: my_pool -# servers: [] +# upstreams: +# - name: my_pool +# servers: [] # servers: # - port: 80 # server_name: demo.example.com diff --git a/templates/etc/nginx/sites-available/vhost.j2 b/templates/etc/nginx/sites-available/vhost.j2 index e07caa8..2983be8 100644 --- a/templates/etc/nginx/sites-available/vhost.j2 +++ b/templates/etc/nginx/sites-available/vhost.j2 @@ -1,12 +1,14 @@ #jinja2: lstrip_blocks: True {{ ansible_managed | comment }} +{% if item.upstreams is defined and item.upstreams %} +{% for upstream in item.upstreams %} -{% if item.upstream is defined and item.upstream %} -upstream {{ item.upstream.name }} { - {% for upserver in item.upstream.servers %} +upstream {{ upstream.name }} { + {% for upserver in upstream.servers %} server {{ upserver }}; {% endfor %} } +{% endfor %} {% endif %} {% for server in item.servers %}