Learning Ansible
You can request Ansible to run a few tasks at a time. This can be useful to do a “gradual deployment”, where some nodes will be modified first, and others later.
- name: Do something on the webservers hosts
hosts: webservers
serial: 2
tasks:
- name: Say something
debug:
msg: "Hello world!"
- name: Say something else
debug:
msg: "Hello world again!"
If the above playbook is run on 4 nodes, it will run on 2 nodes at a time in this order:
There are some tricks to serial
:
Serial | Description |
---|---|
1 |
Run on all nodes at once. |
10% |
Run on 10% of the nodes at once. |
[1, 2, 3] |
Run on 1 node, then 2 nodes, then 3 nodes. |
["10%", "20%", "100%"] |
Run on 10% of the nodes, then 20% of the nodes, then all (remaining) of the nodes. |
Write a playbook that runs on the first 10%, next, 3 nodes, finally 100% of the nodes. Add a simple task that displays a message.
Make sure the inventory contains at least 10 nodes. You can use a pattern in the inventory: node-[1:10] ansible_connection=local
.
Have a look at this solution.