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

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/47133e410b037aa8b214547cfe9e7d1b%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to