Add examples of the 'serial' and 'delegate_to' keywords to examples/playbooks.

This commit is contained in:
Michael DeHaan 2012-08-18 10:11:17 -04:00
parent 898d7676f7
commit 9aa41f075d
2 changed files with 53 additions and 0 deletions

View file

@ -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

View file

@ -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