On 24.02.2018 14:08, Willem D'Haese wrote:
> I'm trying to create a new string from the keys of a dictionary in a
> Ninja
You probably mean Jinja and not Ninja ;-)
> {% set ssh_allowusers = 'root' %}
> {% for x in dictusers %}
> {{ssh_allowusers }} + {{ x }}
> {% set ssh_allowusers = ssh_allowusers ~ ' ' ~ x %}
> {{ssh_allowusers }}
> {% endfor %}
> Post Loop: {{ssh_allowusers }}
>
> dict_users:
>
> dictusers:
> willemdh:
> shell: /bin/zsh
> groups: wheel
> shortname: Willem
> ansi:
> shell: /bin/sh
> groups: sysusers,wheel
> shortname: Willem
>
> But output is:
>
> root + ansi
> root ansi
> root ansi + willemdh
> root ansi willemdh
> Post Loop: root
>
> Why would the variable reset to 'root' after the loop?
A variable set in a block is not available outside the block.
You can read more about it here
http://jinja.pocoo.org/docs/dev/templates/#assignments
--
Kai Stian Olstad