On 20.02.2018 10:46, 'deewon' via Ansible Project wrote:
vars:
db_roles:
user1:
- { db: "lab2", privs: "READ,DELETE" }
user2:
- { db: "lab1", privs: "INSERT,DELETE" }
- { db: "lab2", privs: "UPDATE" }
To do this, I created a jinja2 template that looks like the below:
{% for item in db_roles %}
{% for dict_item in db_roles[item] %}
,
{ "db" : "admin", "userName" : "{{ item }}",
"roles" : [
{% for dbpriv in dict_item.privs.split(',') %}
{
"db" : "{{ dict_item.db }}",
"role" : "{{ dbpriv }}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
}
{% endfor %}
{% endfor %}
You need to move your { "db" up one level.
{% for item in db_roles %}
,
{ "db" : "admin", "userName" : "{{ item }}",
{% for dict_item in db_roles[item] %}
"roles" : [
{% for dbpriv in dict_item.privs.split(',') %}
{
"db" : "{{ dict_item.db }}",
"role" : "{{ dbpriv }}"
}
{%- if not loop.last %},{% endif %}
{% endfor %}
{% endfor %}
]
}
{% endfor %}
I also added a "-" to the "if" so it comes after "}" and not on a
newline.
--
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/04f795072e34ec51281c7f2bdb98df97%40olstad.com.
For more options, visit https://groups.google.com/d/optout.