ansible中的group_by模块借助Facts可以用来创建匹配特定标准的主机的动态组。
- hosts: all
tasks:
- name: Create a group of all hosts by operating system
group_by: key={{ansible_distribution}}-{{ansible_distribution_version}}
#组名中间不要留空格
- hosts: CentOS-6.2 #CentOS-6.2即引用上面group_by创建的value
tasks:
- name: ping all CentOS 6.2 hosts
ping:
- hosts: CentOS-6.3
tasks:
- name: ping all CentOS 6.3 hosts
ping:
附:
Facts are information derived from speaking with your remote systems.
#ansible hostname -m setup
本文出自 “11524698” 博客,请务必保留此出处http://11534698.blog.51cto.com/11524698/1825989
原文地址:http://11534698.blog.51cto.com/11524698/1825989