Skip to content

Instantly share code, notes, and snippets.

/looptest.sls Secret

Created April 14, 2017 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/216d66ea8d26a6cf6f35b532a6b0f07a to your computer and use it in GitHub Desktop.
Save anonymous/216d66ea8d26a6cf6f35b532a6b0f07a to your computer and use it in GitHub Desktop.
Demonstrates scoping of variables inside and out of a loop
{% set itlist = ['alpha', 'betta', 'gamma', 'delta', 'echo'] %}
{% set str = 'started--' %}
{% for item in itlist %}
{% set str = str ~ item %}
{% if not loop.last %}
{% set str = str ~ ', ' %}
{% endif %}
print str during loop for item {{ item }}:
test.configurable_test_state:
- name: added item {{ item }}
- changes: False
- result: True
- comment: {{ str }}
{% endfor %}
str after loop:
test.configurable_test_state:
- name: str after loop
- changes: False
- result: True
- comment: {{ str }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment