How to get an Ansible check to run only once in a playbook?


As a safeguard against using an outdated playbook, I’d like to ensure that I have an updated copy of the git checkout before Ansible is allowed to modify anything on the servers.

This is how I’ve attempted to do it. This action is located in a file included by all play books:

The problem is that this command is run once for each node Ansible connects to, instead of only once for each playbook run. How can I avoid that?


When I fist wrote my answer, Ansible had no built-in support for running a task only once per playbook, not once per affected host that the playbook was run on. However, support for this was introduced with run_once: true in Ansible version 1.7.0 (released on 2014-08-06). With this feature, the example task definition from the question should be changed to

to accomplish what is asked for.

Leave a Reply