Member-only story
Ansible troubleshooting — Error run-once
How to Solve the Ansible Error run-once
Understanding the Ansible Playbook Error: run-once
When developing Ansible playbooks, it’s crucial to ensure efficient execution and adhere to best practices. This includes using strategies that align with the desired behavior of your tasks and plays. In the world of Ansible, the run_once
directive is a powerful tool. It is used to ensure that a particular task runs only once in a playbook. However, its use can become problematic if not handled correctly, especially when used in conjunction with the strategy: free
configuration.
What is run_once
?
In Ansible, the run_once
directive allows you to specify that a task should execute only once, regardless of how many hosts are involved in the playbook. This is particularly useful when you have a task that should be performed only on the control node or a single target host, even in a scenario where multiple hosts are being managed
Here’s a quick example:
- name: Ensure setup is done once
hosts: all
gather_facts: no
tasks:
- name: Perform setup
ansible.builtin.debug:
msg: "This setup should run once"
run_once: true