Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print string when "item exists in a list" in Jinja2 template

I'm trying to populate nsswitch.conf with values that are determined from a list. The list is of string:

openldap_nsswitch:
  - group
  - hosts
  - passwd
  - shadow

If the string is in the list I want to output something in the template.

passwd:         compat {% if openldap_nsswitch contains passwd %}ldap{% endif %}

How can I write a string only if my list contains a specific element?

like image 328
Ken J Avatar asked Nov 28 '17 22:11

Ken J


Video Answer


1 Answers

Here you are:

passwd:         compat{{ ' ldap' if ('passwd' in openldap_nsswitch) else ‘’ }}
like image 198
techraf Avatar answered Sep 19 '22 05:09

techraf