双花括号({{)在YAML文件中是什么意思(由Ansible使用)?

Aru*_*run 13 ansible

我对Ansible很新,并试图理解YAML文件.因为我不清楚这条线 - file: dest={{ '{{' }} docroot {{ '}}' }.有人可以解释一下这些花括号'{{''}}'在做什么吗?

- name: Create Web Root

    when: nginxinstalled|success

    file: dest={{ '{{' }} docroot {{ '}}' }} mode=775 state=directory owner=www-data group=www-data

  notify:

      - Reload Nginx
Run Code Online (Sandbox Code Playgroud)

Noa*_*nos 11

我发现Ansible 文档中的这个YAML 语法概述非常有用。

它说双花括号{{ variable }}用于评估表达式。虽然区分单个大括号(在冒号之后),但用于声明字典。例如:

satchmo: {name: Louis Armstrong, music: Jazz, instrument: Trumpet}
Run Code Online (Sandbox Code Playgroud)

另外,请查看Jinja 模板设计器文档。Jinja 模板在 YAML 之前呈现,这意味着它在 Ansible 执行之前进行评估。

{% ... %} for Statements
{{ ... }} for Expressions to print to the template output
{# ... #} for Comments not included in the template output
#  ... ## for Line Statements
Run Code Online (Sandbox Code Playgroud)

  • @boardtc 也许那是 Helm?他们使用“{{-”来左边修剪空白,使用“-}}”来右边修剪空白。https://helm.sh/docs/chart_template_guide/control_structs/ (4认同)

Aks*_*pte 7

Ansible使用jinja2模板

{{ }}被用来评估从传递的上下文内它们的表达.

所以{{ '{{' }}评估字符串{{

而while表达式{{ docroot }}被写入模板,其中docroot可能是另一个模板变量

有关详细信息,请参阅https://docs.ansible.com/ansible-container/container_yml/template.html.

  • 那么在给出的例子中`{{ '{{' }}` 的目的究竟是什么? (2认同)