Running a task only once
At times, a specific task in a role may need to be executed only once during a playbook execution, even though the role is applied to many hosts. This could be achieved with the run_once
conditional:
name: initialize wordpress database script: initialize_wp_database.sh run_once: true
Since we are using the run_once
option, the preceding task would run on the first host in the inventory that the role is being applied to. All consequent hosts would skip this task.