Jinja question

I have a SALT specific Jinja question. I have a file that needs a certain line of text at the top if it is a VMware vm. I have jinja code that determines this but I am not sure how it renders the file.

This is the jinja:

{% if salt['grains.get']('virtual','KVM') == 'VMware' %}
tinker panic 0
{% endif %}

When the file is rendered and placed on the machine it looks like this:

Blank line    
tinker panic 0
Blank line

Does the jinja render as blank lines here? Should I change it to

{% if salt['grains.get']('virtual','KVM') == 'VMware' %}tinker panic 0{% endif %}

Posted Jan 15, 2019, 2:32 PM UTC

23
Seven-Prime•

You'll want to use the line ending modification thingies. The hyphens. They remove new lines.

​

 {% if salt['grains.get']('virtual','KVM') == 'VMware' -%}
tinker panic 0
{%- endif %} 

​

4
TinyRickSystemsOP•

Damn line ending modification thingies, always forgetting about them

2
xandrellas•

Yeah I had to learn Jinja2 whitespace control the hard way.

​

But - once understood...pretty cool stuff.

1