From 5a88953f2dc977871bb06878763a332816e08c94 Mon Sep 17 00:00:00 2001 From: Wilfried Roset Date: Mon, 15 Feb 2021 18:11:22 +0100 Subject: [PATCH] Fix consul-template.cfg broken newlines Without `#jinja2: trim_blocks:False` the resulting file is invalid, example: ``` consul = "127.0.0.1:8500" log_level = "INFO" template { source = "/opt/consul-template/templates/haproxy.ctmpl" destination = "/etc/haproxy/haproxy.cfg" command = "systemctl reload haproxy.service" perms = 0600 backup = truewait = 2s} ``` Hence making consul-template --- templates/consul-template.cfg.j2 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/templates/consul-template.cfg.j2 b/templates/consul-template.cfg.j2 index 42d1351..6ccd17a 100644 --- a/templates/consul-template.cfg.j2 +++ b/templates/consul-template.cfg.j2 @@ -1,13 +1,14 @@ +#jinja2: trim_blocks:False consul = "{{ consul_template_consul_server }}:{{ consul_template_consul_port }}" -{% if consul_template_log_level %} +{% if consul_template_log_level -%} log_level = "{{consul_template_log_level}}" -{% endif %} -{% if consul_template_wait is defined %} +{% endif -%} +{% if consul_template_wait is defined -%} wait = "{{consul_template_wait}}" -{% endif %} -{% if not consul_template_use_config_dir %} -{% if consul_template_templates %} -{% for template in consul_template_templates %} +{% endif -%} +{% if not consul_template_use_config_dir -%} +{% if consul_template_templates -%} +{% for template in consul_template_templates -%} template { source = "{{ consul_template_home }}/templates/{{ template.name }}" destination = "{{ template.dest }}" @@ -15,6 +16,6 @@ template { {% if template.perms is defined %}perms = {{ template.perms }}{% endif %} {% if template.backup is defined %}backup = {{ template.backup|lower }}{% endif %} {% if template.wait is defined %}wait = {{ template.wait|lower }}{% endif %} -}{% endfor %} -{% endif %} -{% endif %} +}{% endfor -%} +{% endif -%} +{% endif -%}