salt stack: use state jinja variables in template

Solution 1:

You can pass any value you need to the template by using the defaults keyword. In your case, this would be:

{% for vpnuser in salt['pillar.get']('openvpn') %}
/etc/openvpn/ccd/{{ vpnuser }}:
  file.managed:
    - template: jinja
    - source: salt://openvpn/ccdtemplate
    - defaults:
        vpnuser: {{ vpnuser }}
{% endfor %}

This is documented in http://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html