HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

Jinja syntax error: missing endif, in spite of providing it

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
errorprovidingspitesyntaxmissingjinjaendif

Problem

I am using Salt 2019.2.0 version and below is my state file where I am using if condition to check the values and run states if it's a match. Even if I have provided endif, it says Jinja looking for missing endif tag. Any help please?

CODE:
{% if salt'pillar.get' == 'FI' and salt'pillar.get' == 'master' %}
dataimport-script:
file.managed:
- name: /opt/bin/DataImport.py
- source: salt://files/DataImport.py

dataimport-crontab:
file.managed:
- name: /etc/cron.d/solr-dataimport
- contents: |
# # set up data import for FI every 2 minutes
/2 * root /usr/bin/python /opt/bin/DataImport.py
{% elif salt'pillar.get' in ['slave','ds'] and salt'pillar.get' == 'FI' %}
update-fi-solrconfig:
file.replace:
- name: {{ salt'pillar.get' }}/data/{{ salt'pillar.get' }}/conf/solrconfig.xml
- pattern: '"autoDeletePeriodSeconds">30'
- repl: '"autoDeletePeriodSeconds">-1'
{% endif %}


ERROR:

local:

Data failed to compile:
----------
Rendering SLS 'base:solr.install-solr' failed: Jinja syntax error: Unexpected end of template. Jinja was looking for the following tags: 'endif'. The innermost block that needs to be closed is 'if'.; line 205
---

[...]

update-fi-solrconfig:
file.replace:
- name: {{ salt['pillar.get']('solr:home_dir') }}/data/{{ salt['pillar.get']('spade:Corename') }}/conf/solrconfig.xml
- pattern: '"autoDeletePeriodSeconds">30'
- repl: '"autoDeletePeriodSeconds">-1'
{% endif %} <======================

Solution

There is no error in what you have posted here. The error lies elsewhere in your code which you did not include in the OP. Using the Jinja live parser, when pasting in:

{% if spade.corename == 'FI' and spade.nodetype == 'master' %}
dataimport-script:
  file.managed:
    - name: /opt/bin/DataImport.py
    - source: salt://files/DataImport.py

dataimport-crontab:
  file.managed:
    - name: /etc/cron.d/solr-dataimport
    - contents: |
                # # set up data import for FI every 2 minutes
                */2 * * * * root /usr/bin/python /opt/bin/DataImport.py
{% elif spade.nodetype in ['slave','ds'] and spade.corename == 'FI' %}
update-fi-solrconfig:
  file.replace:
    - name: {{ salt['pillar.get']('solr:home_dir') }}/data/{{ 
salt['pillar.get']('spade:Corename') }}/conf/solrconfig.xml
    - pattern: '"autoDeletePeriodSeconds">30'
    - repl: '"autoDeletePeriodSeconds">-1'
{% endif %}


With a pillar of:

spade:
  corename: FI
  nodetype: master


Everything renders just fine. This tells me there is nothing wrong with your snippet. The fact that your error indicates you have at least 205 lines of code, but the example has far less tells me the issue was with another "if" block further up in your code.

Code Snippets

{% if spade.corename == 'FI' and spade.nodetype == 'master' %}
dataimport-script:
  file.managed:
    - name: /opt/bin/DataImport.py
    - source: salt://files/DataImport.py

dataimport-crontab:
  file.managed:
    - name: /etc/cron.d/solr-dataimport
    - contents: |
                # # set up data import for FI every 2 minutes
                */2 * * * * root /usr/bin/python /opt/bin/DataImport.py
{% elif spade.nodetype in ['slave','ds'] and spade.corename == 'FI' %}
update-fi-solrconfig:
  file.replace:
    - name: {{ salt['pillar.get']('solr:home_dir') }}/data/{{ 
salt['pillar.get']('spade:Corename') }}/conf/solrconfig.xml
    - pattern: '"autoDeletePeriodSeconds">30'
    - repl: '"autoDeletePeriodSeconds">-1'
{% endif %}
spade:
  corename: FI
  nodetype: master

Context

StackExchange DevOps Q#11679, answer score: 2

Revisions (0)

No revisions yet.