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 行。