Ansible - local_action parameter
by
Jeremy Canfield |
Updated: March 29 2021
| Ansible articles
By default, modules are run against your managed nodes (the target systems). The local_action parameter can be used to run a module on the control node (that's your Ansible server). Refer to these articles for a better understanding of how tasks are run against the control node or managed nodes.
In this example, the local_action parameter is used with the file module to remove a file on the control node.
- name: remove foo.txt on control node
local_action:
module: file
path: /tmp/foo.txt
state: absent
Often, the run_once parameter is used so that the task is only ran one time on the control node.
- name: remove foo.txt on control node
local_action:
module: file
path: /tmp/foo.txt
state: absent
run_once: true
Running this task should produce the following.
TASK [remove foo.txt on control node]
changed: [server1.example.com -> localhost]
Did you find this article helpful?
If so, consider buying me a coffee over at