我在模板中有以下循环:
{% for host in groups['dbnodes'] %}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
问题是它给出了 ip 列表中的输出,我需要它以逗号分隔的值。知道如何实现这一目标吗?
我得到的答案是这样的:
10.0.0.190
10.0.0.117
10.0.0.151
Run Code Online (Sandbox Code Playgroud)
但我需要这样的:
10.0.0.190,10.0.0.117,10.0.0.151
Run Code Online (Sandbox Code Playgroud)
对 Jinja2 模板的快速修复:
{% for host in groups['dbnodes'] -%}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}{% if not loop.last %},{% endif %}
{%- endfor %}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5520 次 |
最近记录: |