ansible/examples/playbooks/delegation.yml

40 lines
1.4 KiB
YAML
Raw Normal View History

---
# 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
2012-08-21 00:26:05 +02:00
# here's an alternate notation if you are delegating to 127.0.0.1, you can use 'local_action'
# instead of 'action' and leave off the 'delegate_to' part.
#
# - local_action: command echo taking out of rotation $inventory_hostname
- 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