Range in Jinja in statefiles?

616 views
Skip to first unread message

J C Lawrence

unread,
Feb 5, 2014, 9:44:21 PM2/5/14
to salt-...@googlegroups.com
Shouldn't "range" work in a Jinja in a statefile?

{% range ndx from 1 to 3 %}
qa-mesh-{{ ndx }}:
cloud.present:
- name: qa-mesh-{{ ndx }}
- provider: qa
- image: ami-c30360aa
- size: m3.xlarge
- ssh_username: ubuntu
- rename_on_destroy: True
- delvol_on_destroy: True
- block_qaice_mappings:
- DeviceName: /dev/xvdb
VirtualName: ephemeral0
{% endrange %}

But no:

[CRITICAL] Rendering SLS "base:env_qa" failed: Jinja syntax error:
Encountered unknown tag 'range'.; line 31

---
[...]
{% range ndx from 1 to 3 %} <======================
qa-mesh-{{ ndx }}:
cloud.present:
- name: qa-mesh-{{ ndx }}
- provider: qa
- image: ami-c30360aa
[...]


-- JCL

David Anderson

unread,
Feb 5, 2014, 9:58:15 PM2/5/14
to salt-...@googlegroups.com
Try

{% for ndx in range(1,3) %}
...
{% endfor %}
--
Dave

David Anderson

unread,
Feb 5, 2014, 9:58:53 PM2/5/14
to salt-...@googlegroups.com
Actually, should be range(1,4)
--
Dave

J C Lawrence

unread,
Feb 6, 2014, 12:50:24 AM2/6/14
to salt-...@googlegroups.com
Yeah, and that's much like what I ended up doing, but surely a Jinja
template should support Jinja features like Range? Principle of least
surprise and all that.

-- JCL

J C Lawrence

unread,
Feb 6, 2014, 12:52:26 AM2/6/14
to salt-...@googlegroups.com
The supporting Jinja docs:

http://wsgiarea.pocoo.org/jinja/docs/loops.html

-- JCL

David Anderson

unread,
Feb 6, 2014, 1:04:46 AM2/6/14
to salt-...@googlegroups.com
http://wsgiarea.pocoo.org/jinja/docs/index.html

"Welcome in the old Jinja Documentation. This documentation explains all
important parts of the Jinja pre 1.0 Template Engine.
For an up-to-date documentation check out the new Jinja webpage at
jinja.pocoo.org."

http://jinja.pocoo.org/docs/templates/#range
--
Dave
Reply all
Reply to author
Forward
0 new messages