<p>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 <a href="https://cryptic-cliffs-32040.herokuapp.com/" rel="nofollow noreferrer">Jinja live parser</a>, when pasting in:</p>
<pre><code>{% 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: '&quot;autoDeletePeriodSeconds&quot;&gt;30'
    - repl: '&quot;autoDeletePeriodSeconds&quot;&gt;-1'
{% endif %}
</code></pre>
<p>With a pillar of:</p>
<pre><code>spade:
  corename: FI
  nodetype: master
</code></pre>
<p>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 &quot;if&quot; block further up in your code.</p>

CC BY-SA 4.0
2021-05-12T02:54:17.070Z
2021-05-12T02:54:17.070Z
James Shewey
<p>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?</p>
<p><strong>CODE</strong>:</p>
<pre class="lang-yml prettyprint-override"><code>{% if salt['pillar.get']('spade:Corename') == 'FI' and salt['pillar.get']('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 salt['pillar.get']('spade:NodeType') in ['slave','ds'] and salt['pillar.get']('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: '&quot;autoDeletePeriodSeconds&quot;&gt;30'
    - repl: '&quot;autoDeletePeriodSeconds&quot;&gt;-1'
{% endif %}
</code></pre>
<p><strong>ERROR</strong>:</p>
<pre><code>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: '&quot;autoDeletePeriodSeconds&quot;&gt;30'
- repl: '&quot;autoDeletePeriodSeconds&quot;&gt;-1'
{% endif %} &lt;======================
</code></pre>

CC BY-SA 4.0
2020-09-28T14:23:16.433Z
The mismatch might have started in `solr.install-solr` as indicated in the error.
seshadri_c
<salt><jinja>
Jinja syntax error: missing endif, in spite of providing it
user22405
# Jinja syntax error: missing endif, in spite of providing it

(Asked by: username_0 on 2020-05-23)

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']('spade:Corename') == 'FI' and salt['pillar.get']('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 salt['pillar.get']('spade:NodeType') in ['slave','ds'] and salt['pillar.get']('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 %}

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 %} <======================

**Tags:** salt, jinja

> **Comments:**
> **username_1**: The mismatch might have started in `solr.install-solr` as indicated in the error.  

---

## 1 answers

### Answer by username_2 on 2021-05-12. Score: 2

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.


---

