> ## Content Index
> Fetch the complete content index at: https://www.andreacasarin.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Ansible forks/serial on a task level
- URL: https://www.andreacasarin.com/2022/06/11/ansible-forks-on-a-task-level/
- Published: 2022-06-11T10:17:19.000Z
- Updated: 2026-10-30T11:28:14.000Z
- Author: Andrea Casarin
- Tags: #Import 2023-03-16 18:53

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](https://docs.ansible.com/ansible/latest/user%5Fguide/playbooks%5Fstrategies.html?ref=andreacasarin.com#id2) at a configuration level
- [serial](https://docs.ansible.com/ansible/latest/user%5Fguide/playbooks%5Fstrategies.html?ref=andreacasarin.com#setting-the-batch-size-with-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](https://github.com/ansible/ansible/issues/12170?ref=andreacasarin.com) and, although not documented yet it's been implemented:

- [https://github.com/ansible/ansible/pull/42528](https://github.com/ansible/ansible/pull/42528?ref=andreacasarin.com)
- [https://github.com/ansible/ansible/pull/60702](https://github.com/ansible/ansible/pull/60702?ref=andreacasarin.com)

So here we go:

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

```