{% set zone = salt['pillar.get']('containers:zone', 'public') %} {% for name, args in salt['pillar.get']('containers', {} ).items() %} {% if args['ports'] is defined %} Defining firewalld service for {{ name }}: firewalld.service: - name: {{ name }} - ports: {%- for port in args['ports'] %} - {{ port['host'] }}/tcp {%- endfor %} adding service {{ name }} to {{ zone }} zone: firewalld.present: - name: {{ zone }} - services: - {{ name }} {% endif %} {% endfor %}