7

我正在尝试使用从列表中确定的值填充 nsswitch.conf。该列表是字符串:

openldap_nsswitch:
  - group
  - hosts
  - passwd
  - shadow

如果字符串在列表中,我想在模板中输出一些东西。

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

仅当我的列表包含特定元素时,如何编写字符串?

4

2 回答 2

12

给你:

passwd:         compat{{ ' ldap' if ('passwd' in openldap_nsswitch) else ‘’ }}
于 2017-11-28T22:52:27.153 回答
1

Compat 对我不起作用:

{% if is in('passwd', openldap_nsswitch) %} ldap {% endif %}

另外,我是在 ansible 之外做这个的。

于 2019-11-13T21:17:43.333 回答