Hi
I’m running a deployment that consists of different plays, some of which are already written that I would like to reuse. There’s about one one play for each stage:
Remove server from cluster
Shut down the server
Provision a new server to replace it
When running, I need each set of plays to run on one server at a time, so setting ‘serial’ on the play level isn’t enough. I know I can run another ansible-playbook instance with the command module, but then I wouldn’t see the progress for each play. I guess I can copy-paste my existing playbooks and play with delegate_to to achieve what I want, but that feels wrong. What I’m doing currently is splitting my playbook run to several pieces and gluing them with bash, looping when necessary on a single playbook.
It feels like Ansible doesn’t support this use case well currently. Is there a better way to solve that than using bash? Are there features in the pipeline to help with this case?
+1
I have this problem a lot when I use delegate_to with multiple targets making a request of a single delegate. Lock conflicts cause intermittent failure.
That won’t help me. If i have one play to remove a node from a cluster, one to shut it down and one to provision a new one, i need the tasks in all of them to run for each host. Removing all nodes, then shutting them all down, etc isn’t good.
Ideally I’d have one task for each. But when that task is a play by itself, that’s where my problem is.
so I think you need 4 plays, make the tasks into their own files, use
- include in all plays, you have the same tasks but use the different
plays for each of the different needs.
plays 1,2,3 as you have now, play 4, with serial: 1, uses tasks from
play 1, 2 and 3 in order.
Thanks Brian, that looks like it could work. I’m not sure I like doing a small refactor for this though. Plus I still have to copy the ‘role:’ sections. Eh… I’ll think of something. Thanks!