I'd like to create two playbooks, one to stop an environment, another to start it.
Part of the environment is a RabbitMQ cluster, for which stop/start order is quite important, specifically the last node stopped needs to be the first node started.
I was wondering if there is a way to specify a reverse order for running a task against a group. That way I could apply the stop with serial 1, and the start with serial 1 and reverse group order.
I haven't found a way to do that but to define the rabbitmq host group twice (under different names), in inverted order, which seems a bit distasteful.
Also attempted following:
- hosts: "{ myhostsgroup | sort(reverse=False) }"
serial: 1
And
- hosts: "{ myhostsgroup | reverse }"
serial: 1
But result stays the same, whichever case and its variation (reverse=True, reverse|list) is attempted
Any help would be greatly appreciated.
Playbook execution. A playbook runs in order from top to bottom. Within each play, tasks also run in order from top to bottom.
What is Ansible pre_tasks? Ansible pretask is a conditional execution block that runs before running the play. It can be a task with some prerequisites check (or) validation.
You can do rolling updates in Ansible using the serial keyword. This gives you the ability to specify the number of hosts you want to execute against at a time on a per-playbook basis. This also allows you to slowly ramp up your deployment in batches by providing an increasing list.
Running parallel tasks in Ansible is not a problem. Ansible or in fact any kind of configuration management tool was meant for this. They are suppossed to be provisioning multiple host systems simultaneously and hence parallel execution of jobs is one of their strengths.
You can create dynamic groups in runtime:
---
- hosts: localhost
gather_facts: no
tasks:
- add_host:
name: "{{ item }}"
group: forward
with_items: "{{ groups['mygroup'] }}"
- add_host:
name: "{{ item }}"
group: backward
with_items: "{{ groups['mygroup'] | reverse | list }}"
- hosts: forward
gather_facts: no
serial: 1
tasks:
- debug:
- hosts: backward
gather_facts: no
serial: 1
tasks:
- debug:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With