shell> cat list1.txt.j2
All hosts in the group are:
{%- for host in ansible_play_hosts_all -%}
{{ host }}{% if not loop.last %}, {% endif %}{% endfor %}
shell> cat list2.txt.j2
All hosts in the group are:
{%- for host in groups.all -%}
{{ host }}{% if not loop.last %}, {% endif %}{% endfor %}
A: 有 2 个标准选项。特殊变量
ansible_play_hosts_all
或groups
. 例如,与库存两个模板
和剧本
放弃所有远程主机