Andrea Casarin

Andrea Casarin

Published on: 6/11/2022, 10:17:19 AM - Reading time: 1 minute

Ansible forks/serial on a task level

If your inventory contains the same host multiple times (think dynamic inventories or something defined via Terraform) and then you run a playbook against that (eg. target: all) you'll end up trying to run the same tasks simultaneously on the same host.

That's not usually an issue, however some tasks require a lock (eg. apt install pkg) thus breaking for errors or timeouts.

Ansible has some attributes to manage this situations, like:

  • forks at a configuration level
  • serial at a playbook level

What if you can define it on a task level? That would be great since you could then only limit tasks which actually require locks instead of slowing down everything.

Looks like it has been asked before: and, although not documented yet it's been implemented:

So here we go:

- name: Testcommand: 
  echo 'test'
  throttle: 1