mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add examples of the 'serial' and 'delegate_to' keywords to examples/playbooks.
This commit is contained in:
parent
898d7676f7
commit
9aa41f075d
2 changed files with 53 additions and 0 deletions
19
examples/playbooks/batch_size_control.yml
Normal file
19
examples/playbooks/batch_size_control.yml
Normal 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
|
||||
|
||||
|
34
examples/playbooks/delegation.yml
Normal file
34
examples/playbooks/delegation.yml
Normal 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
|
||||
|
Loading…
Reference in a new issue