From 9aa41f075d81d60e5f13c496b7ba7bbddc4107aa Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 18 Aug 2012 10:11:17 -0400 Subject: [PATCH] Add examples of the 'serial' and 'delegate_to' keywords to examples/playbooks. --- examples/playbooks/batch_size_control.yml | 19 +++++++++++++ examples/playbooks/delegation.yml | 34 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 examples/playbooks/batch_size_control.yml create mode 100644 examples/playbooks/delegation.yml diff --git a/examples/playbooks/batch_size_control.yml b/examples/playbooks/batch_size_control.yml new file mode 100644 index 00000000000..970bc2a2a19 --- /dev/null +++ b/examples/playbooks/batch_size_control.yml @@ -0,0 +1,19 @@ +# ordinarily, without the 'serial' keyword set, ansible will control all of your machines in a play at once, in parallel. +# if you want to perform a rolling update, so that each play completes all the way through on a certain number of hosts +# before moving on to the remaining hosts, use the 'serial' keyword like so: + +--- +- hosts: all + serial: 3 + +# now each of the tasks below will complete on 3 hosts before moving on to the next 3, regardless of how many +# hosts are selected by the "hosts:" line + + tasks: + + - name: ping + action: ping + - name: ping2 + action: ping + + diff --git a/examples/playbooks/delegation.yml b/examples/playbooks/delegation.yml new file mode 100644 index 00000000000..766a69ed637 --- /dev/null +++ b/examples/playbooks/delegation.yml @@ -0,0 +1,34 @@ +--- + +# this is an example of how we can perform actions on a given host on behalf of all the hosts +# in a play. +# +# The two main uses of this would be signalling an outage window for hosts that +# we are going to start upgrading, or to take a machine out of rotation by talking to a load +# balancer. +# +# This example cheats by replacing the load balancer script with the 'echo' command, +# leaving actual communication with the load balancer as an exercise to the reader. In reality, +# you could call anything you want, the main thing is that it should do something with +# $inventory_hostname + +# NOTE: see batch_size_control.yml for an example of the 'serial' keyword, which you almost certainly +# want to use in this kind of example. Here we have a mocked up example that does something to +# 5 hosts at a time + +- hosts: all + serial: 5 + + tasks: + + - name: take the machine out of rotation + action: command echo taking out of rotation $inventory_hostname + delegate_to: 127.0.0.1 + + - name: do several things on the actual host + action: command echo hi mom $inventory_hostname + + - name: put machine back into rotation + action: command echo inserting into rotation $inventory_hostname + delegate_to: 127.0.0.1 +