Is there are way to prevent concurrent execution of a single task?

I have a local_action using the lineinfile module to modify a single file on Ansible control server on behalf of each host in the inventory active for the current play, using information obtained from an earlier task in the play. The problem is the task gets run in parallel for each host, and they end up stomping on each other’s changes.

Is there some way to prevent parallel execution for just one task, or to apply some sort of synchronization to the task?

I think I solved my own problem.

Here’s what I came up with:
run_once: yes
with_items: “{{ ansible_play_hosts }}”

Then I made sure to qualify any host-specific variable references with “hostvars[item].”