【发布时间】:2017-01-25 16:03:38
【问题描述】:
我正在尝试从仅在单个组中运行的剧本中获取清单文件中所有主机的 IP 列表。
假设以下库存文件:
[dbservers]
db1.example.com
db2.example.com
[webservers]
www1.example.com
www2.example.com
还有剧本:
---
- hosts: dbservers
roles:
- dosomething
还有做某事的角色:
- name: print all host ips
template: src=hosts.j2 dest=/tmp/hosts.txt
还有 hosts.j2 模板:
{% for host in hostvars %}
{{ hostvars[host].ansible_eth0.ipv4.address }}
{% endfor %}
问题:
运行此程序时,我只列出了 dbserver ip,而不是所有 ip
问题:
我怎样才能从这个剧本中访问整个库存?在剧本中将主机更改为 all 是可行的,但随后 dosomething 剧本也在所有主机上运行,这不是我想要的。我只想要 dbservers 上的列表。
【问题讨论】: