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

78 views
Skip to first unread message

Richard Eggert

unread,
Oct 7, 2016, 10:48:34 AM10/7/16
to Ansible Project
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?

Richard Eggert

unread,
Oct 7, 2016, 11:30:05 AM10/7/16
to Ansible Project
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]."
Reply all
Reply to author
Forward
0 new messages