Ansible 使用带有 blockinfile 的模板
Ansible use a template with blockinfile
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 %}
这似乎是一个基本用例,我可能想对配置文件进行一些一次性编辑,但仍然需要模板的强大功能。
请注意,使用 with_items
并不能真正满足我的要求,因为我只需要 1 行。
我认为问题在于您在模板中多了一个 {
。
bind *:443 ssl crt {% for cert in certs %}{{cert}} {{% endfor %}
应该是
bind *:443 ssl crt {% for cert in certs %}{{cert}} {% endfor %}
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 %}
这似乎是一个基本用例,我可能想对配置文件进行一些一次性编辑,但仍然需要模板的强大功能。
请注意,使用 with_items
并不能真正满足我的要求,因为我只需要 1 行。
我认为问题在于您在模板中多了一个 {
。
bind *:443 ssl crt {% for cert in certs %}{{cert}} {{% endfor %}
应该是
bind *:443 ssl crt {% for cert in certs %}{{cert}} {% endfor %}