Additional conditions

Skip to first unread message

Igor Stojnov

Feb 18, 2019, 7:51:30 AM2/18/19
to pocoo-libs
Hello all,

I am a noob in using Jinja trying to quickly adapt an existing template, so please bear with me. :-)

Namely, the template is supposed to do the following:

  1. for each ci item (taken from a result in JSON format) which have a name defined and which is not none
  2. set certain custom fields based on certain parameters
  3. convert to JSON
The template is below:

{% for ci in netboxResult.json.results if is defined and is not none -%}
{ "index": { "_index": "{{ item.index }}", "_id": "{{ }}", "_type": "document" } }
{# Formatting IP addresses #}
{% if ci.custom_fields.ipAddresses is defined and ci.custom_fields.ipAddresses is not none %}{% set ips = ci.custom_fields.ipAddresses.split(',') %}{% elif ci.custom_fields.vmIpAddresses is defined and ci.custom_fields.vmIpAddresses is not none %}{% set ips = ci.custom_fields.vmIpAddresses.split(',') %}{% else %}{% set ips = [] %}{% endif %}
{% if ci.custom_fields.environment is defined %}
{ "status": {{ ci.status.label | to_json }}, "environment": {{ ci.custom_fields.environment.label | default(None) | to_json }} }
{% elif ci.custom_fields.vmEnvironment is defined %}
{ "status": {{ ci.status.label | to_json }}, "environment": {{ ci.custom_fields.vmEnvironment.label | default(None) | to_json }} }
{% endif %}
{% endfor %}

What I'd like to do is introduce additional conditions for the CI name - they should not contain the following strings: PDU, shelf, 009, OPTIC, FUSION, PatchPanel.

I've tried a few simple tricks, like adding under "% for ci" a few more conditions for the name - but for some reason it didn't change anything. The output remained the same. I am a bit confused with the ending of the FOR with "-%}".

If someone can help me get me on my way, it would be amazing!

Thanks in advance!


Igor Stojnov

Feb 20, 2019, 9:33:40 AM2/20/19
to pocoo-libs
Hello all,

How can I properly use FOR loop, and then condition next action - based on IF and AND - to check that target property is defined, is not empty and it doesn't contain certain strings? I am especially interested in the latter.

For instance:

{% for ci in netboxResult.json.results if is defined and is not none.... and "does not contain ___" and "does not contain ___" and "does not contain ___"... -%}

Feel free to chime in at any time. :-) Thanks!


Igor Stojnov

Mar 11, 2019, 6:19:39 AM3/11/19
to pocoo-libs
No one?
Reply all
Reply to author
0 new messages