857432 发表于 2016-7-14 12:19:44

ansible module: group_by

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
172.28.15.22    shanghai
172.28.10.113    movie
172.28.11.113    zhuanti
172.28.10.107    openapi
apache mpm由prefork换成event   


deny61.152.175.53;
allow all;




页: [1]
查看完整版本: ansible module: group_by