Ansible - local_action parameter

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 Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter fb564 in the box below so that we can be sure you are a human.