Running ansible playbooks on all nodes in a group is a easy task. Sometimes it is needed to spontaneously pick one node of a group or a group of nodes, for tests. This can be achived many ways. Here it is explained using the --limit option, without changing anything in the files.
How to limit ansible playbook execution without changing a single file i and be able to run following tests:
- pick exactly one node
- pick one particular, well known node
- a small group 3 nodes out of many
- fibonaci number deployment on hudge group of nodes
Let's assume ansible inventory has 100 nodes:
[a99k] a9k1.cgn a9k1.fra a9k1.dus a9k1.muc a9k1.ham a9k1.ber ... a9k1.igs
Limit ansible playbook to only only one node, first entry: 0. The limit is in the brackets [], it starts with a zero and ends with an zero, Zero is the first element. Both zeros are separated by a colon :
Limit ansible playbook to one particular node: a9k1.ber
Limit ansible playbook to 3 nodes in a row, 4-th to 7-th node chosen:
Limit ansible playbook to the fibonacci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, ...
Ansible fibonacci sequence style deployment example, statically
ansible-playbook show-version.yml --limit[0:0]
ansible-playbook show-version.yml --limit[1:1]
ansible-playbook show-version.yml --limit[2:3]
ansible-playbook show-version.yml --limit[4:7]
ansible-playbook show-version.yml --limit[8:13]
ansible-playbook show-version.yml --limit[14:22]
ansible-playbook show-version.yml --limit[23:36]
ansible-playbook show-version.yml --limit[37:58]
ansible-playbook show-version.yml --limit[59:93]
ansible-playbook show-version.yml --limit[94:149]
ansible-playbook show-version.yml --limit[150:239]
ansible-playbook show-version.yml --limit[240:384]
ansible-playbook show-version.yml --limit[385:618]
ansible-playbook show-version.yml --limit[619:996]
ansible-playbook show-version.yml --limit[997:1607]
ansible-playbook show-version.yml --limit[1608:2595]
The fibonacci style deployment is an idea from a blog networking blog run by networkingnerd - automating change with help from fibonacci. Networkingnerd wrote a great article about the fibonacci sequence deployments, in the context of dealing with big node count. Try it out, just to find out.