2012-10-27 17:47:47 +00:00
|
|
|
---
|
|
|
|
# Example playbook to demonstrate the group_by action plugin.
|
2012-10-31 00:00:21 +00:00
|
|
|
#
|
|
|
|
# as we know, the setup module will automatically run in each play, and sets up various
|
|
|
|
# facts. We can then create temporary (in memory only) groups based on those facts, which
|
|
|
|
# are useful ways of selecting similar sets of hosts.
|
|
|
|
#
|
|
|
|
# Additionally, we can use the 'register' keyword in Ansible to set similar variables
|
|
|
|
# and use those for grouping. This is not shown in this example.
|
2012-10-27 17:47:47 +00:00
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
2012-10-31 00:00:21 +00:00
|
|
|
- name: Create a group of all hosts by operating system
|
|
|
|
action: group_by key=${ansible_distribution}-${ansible_distribution_version}
|
|
|
|
|
|
|
|
# the following host group does not exist in inventory and was created by the group_by
|
|
|
|
# module.
|
|
|
|
|
|
|
|
- hosts: CentOS-6.2
|
|
|
|
|
2012-10-27 17:47:47 +00:00
|
|
|
tasks:
|
|
|
|
|
2012-10-31 00:00:21 +00:00
|
|
|
- name: ping all CentOS 6.2 hosts
|
|
|
|
action: ping
|
|
|
|
|
|
|
|
- hosts: CentOS-6.3
|
|
|
|
|
2012-10-27 17:47:47 +00:00
|
|
|
tasks:
|
2012-10-31 00:00:21 +00:00
|
|
|
|
|
|
|
- name: ping all CentOS 6.3 hosts
|
|
|
|
action: ping
|
|
|
|
|
|
|
|
|