How can I order hosts and make Ansible execute plays accordingly? I have an inventory file with two groups and each containing two servers under them.
Something like this:
[GROUP-A:children]
server-1
server-2
[GROUP-B:children]
server-1
server-2
I am trying to achieve a zero downtime deployment for my application and I am looking to make ansible execute playbook in the following order
I have tried serial:
- hosts: "GROUP-A, GROUP-B"
become: false
gather_facts: true
serial: 1
This limits Ansible to execute only on a single server from GROUP-A
, server-1
, which is what I want, but, I also need to jump to GROUP-B
, server-1
and achieve my execution order when the play repeats itself.
There is no real magic in order to mix and match groups, what you could do is to run the first host of both groups then run all the subsequent hosts of those same groups, as demonstrated in the chapter "Using group position in patterns" of the documentation:
- hosts: GROUP-A[0], GROUP-B[0], GROUP-A[1:], GROUP-B[1:]
serial: 1