ansible 获取主机组的主机数量


直接上列子吧:

比如有如下的一个hosts文件,我分别想获取主机组master、node、cluster的主机数量

[master]
192.168.100.28 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='root' host_id=1
192.168.100.29 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='root' host_id=2
192.168.100.30 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='root' host_id=3

[node]
192.168.100.31 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='root' host_id=4

[cluster:children]
master
node

全局变量这样定义:

Master_Count: "{{ groups['master'] | length }}"
Node_Count: "{{ groups['node'] | length }}"
Cluster_Count: "{{ groups['cluster'] | length }}"

得到结果分别是:3、1、4


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM