From cceb99acd55a0cf2fbd40cab88fdc7296eb5587b Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 30 Oct 2012 20:00:21 -0400 Subject: [PATCH] Simplify the group_by example a small bit --- examples/playbooks/group_by.yml | 40 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/examples/playbooks/group_by.yml b/examples/playbooks/group_by.yml index d08f260bd0..bc8548f2fc 100644 --- a/examples/playbooks/group_by.yml +++ b/examples/playbooks/group_by.yml @@ -1,23 +1,35 @@ --- # Example playbook to demonstrate the group_by action plugin. +# +# 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. - hosts: all - # This runs the setup module to gather facts - tasks: - # Use the ansible_machine variable to create a group for every value, - # prefix the group name with 'ansible-' - - action: group_by key=ansible-${ansible_machine} -- hosts: ansible-x86_64 tasks: - # Run ping on all x86_64 machines - - action: ping -- hosts: all - tasks: - # Create a group of all kvm hosts - - action: group_by key=${ansible_virtualization_type}-${ansible_virtualization_role} + - 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 -- hosts: kvm-host tasks: - - action: ping + + - name: ping all CentOS 6.2 hosts + action: ping + +- hosts: CentOS-6.3 + + tasks: + + - name: ping all CentOS 6.3 hosts + action: ping + +