【发布时间】:2021-01-13 10:29:45
【问题描述】:
我想(仅)从 ansible-inventory 获取主机组名称列表,但是我必须使用 grep 根据已知的组名称模式来缩减列表 - 例如
- 输出干净但命令行混乱,需要提前了解组名模式:
ansible-inventory -i inventory/production --list --yaml | grep webserver_.*:$
- 干净的命令行,不需要知道组名模式,但输出混乱:
ansible-playbook my-playbook.yml -i inventory/production --list-hosts
有没有一种干净的方法可以只从库存中提取组名?
hosts.yml 示例:
# NGINX
webserver_1:
hosts:
ws1.public.example.com
webserver_2:
hosts:
ws2.public.example.com
webserver_2:
hosts:
ws2.public.example.com
# EC2 back-ends
backend_ec2_1:
hosts:
be1.internal.example.com
backend_ec2_2:
hosts:
be2.internal.example.com
backend_ec2_3:
hosts:
be3.internal.example.com
[Ansible v2.9.7]
【问题讨论】:
-
请添加样品库存