4

blockinfile似乎用{{模板做基本的替换。该文档没有提到任何模板功能。

但是,似乎不可能做一个完整的模板,比如循环。这失败了template error while templating string: unexpected '%'

  blockinfile:
    dest: /etc/haproxy/haproxy.cfg
    marker: "# {mark} ANSIBLE CONFIG certs"
    block: |
      {% if certs %}
      bind *:443 ssl crt {% for cert in certs %}{{cert}} {{% endfor %}
      {% endif %}

这似乎是一个基本用例,我可能想对配置文件进行一些一次性编辑,但仍然需要模板的力量。

请注意, usingwith_items在这里并没有真正做到我想要的,因为我只需要 1 行。

4

1 回答 1

6

{我认为问题在于您在模板中有额外的内容。

      bind *:443 ssl crt {% for cert in certs %}{{cert}} {{% endfor %}

应该

      bind *:443 ssl crt {% for cert in certs %}{{cert}} {% endfor %}
于 2016-05-05T11:15:25.600 回答