我希望获得在库存文件中定义的主机的公共ip。
[test-sites:children]
test-site-1
[test-site-1]
test-site-1-2 ipv4=192.168.0.1 ipv6=....如何在库存文件中定义“测试站点-1-2”的ipv4和ipv6地址?我已经检查了这的答案,但它给出了所有的地址(公共和私有)。我对库存文件中定义的ips感兴趣。
发布于 2020-04-07 15:48:19
[test-site-1]
test-site-1-2 ipv4=192.168.0.1 ipv6=....问:“如何在库存文件中定义”测试站点-1-2“的ipv4和ipv6地址?”
答:如果剧本在“试验场-1-2”上运行,只需直接引用变量。例如
- hosts: test-site-1-2
tasks:
- debug:
var: ipv4
- debug:
var: ipv6如果其他主机需要这些变量,则需要引用"hostvars“。例如
- hosts: test-site-1
tasks:
- debug:
var: hostvars['test-site-1-2'].ipv4
- debug:
var: hostvars['test-site-1-2'].ipv6见基本库存。
https://stackoverflow.com/questions/61083034
复制相似问题