state/state1/init.sls:
{% for packages in salt['pillar.get']('state1:packages') %}
{{ packages }}:
pkg.installed:
{% endfor %}
pillar/state1/init.sls:
state1:
packages:
{% if grains['fqdn'].startswith("serverA") %}
- package1
- package2
{% endif %}
{% if grains['fqdn'].startswith("serverB") %}
- package3
{% endif %}
The fqdn of the machine i am ussing is "nonameserver" which means that no if statement maches in the pillar. Hence the return vallue of the for loop is empty. Which gives me the following error:
debian:
Data failed to compile:
----------
Rendering SLS "base:state1" failed: Jinja error: 'NoneType' object is not iterable
Thing is how do i tell my for loop in my init.sls state, that if the value returned is empty/not defined, then just proceed and do nothing?