0

I have a template that does the following to sudoers:

{% for a in  cde_admins  %}
User_Alias  CDEADMIN = {{ a }}
{% endfor %}

And I have the variables defined:

cde_admins:
  - foo
  - bar

I am looking for a way that I can iterate through the loop and add a , after foo. So it basically would look like this when i run Ansible:

User_Alias  CDEADMIN = foo, bar

I've tried a few things like adding a join(",") to the Jinja2 syntax but all that does is:

User_Alias  CDEADMIN = f,o,o
User_Alias  CDEADMIN = b,a,r

Can someone point in the right direction to make it so it just adds a comma to the end of foo?

techraf
  • 64,883
  • 27
  • 193
  • 198
ryekayo
  • 2,341
  • 3
  • 23
  • 51

1 Answers1

1

You should use join filter, but on the original list, not on the items:

User_Alias CDEADMIN = {{ cde_admins|join(', ') }}

Only the above line, without the for-loop.

techraf
  • 64,883
  • 27
  • 193
  • 198