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: https://github.com/ansible/ansible/issues/12170 and, although not documented yet it's been implemented:

So here we go:

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