繁体   English   中英

Ansible/Jinja2 星号条件

[英]Ansible/Jinja2 asterisk conditional

尝试通过 Ansible 更新 LDAP 条目,但我想确保 LDAP 主机通配符(“*”)不在主机列表中。 如果我不在 hosts 中使用"*" not in hosts '*' not in hosts “*”,则 Ansible 不喜欢这些。 我也试过 Jinja2 搜索过滤器。 任何帮助都会很棒!

这个问题与星号无关。 这是一个纯粹的 yaml 语法问题

在 yaml 中,如果引用变量,则值的表示将以单引号或双引号开头,然后您将获得值本身和结束引号。 之后, yaml 解析器期待一个 yank <block end> ,在您的特定情况下,一个新行将移动到下一个值定义。

在您的示例中,您的when子句值以引号开头。 所以你必须引用你的全部价值:

when: '"*" not in hosts'
# or
when: "'*' not in hosts"
# even
when: "\"*\" not in hosts"

一个好的和更易读的替代 IMO 是使用 yaml 标量块标记:

when: >-
  "*" not in hosts

想通了。 试图用管道来做,但不需要。

when:
  - var is not regex("\\*")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM