FreeKB - Ansible delegate_to parameter (run task on specific server)
Ansible - delegate_to parameter (run task on specific server)

By default, modules are run against your managed nodes (the target systems). The delegate_to 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 delegate_to parameter is used with the file module to remove a file on the control node.

- name: remove foo.txt on control node
    module: file
    path: /tmp/foo.txt
    state: absent
    delegate_to: localhost

 

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
    module: file
    path: /tmp/foo.txt
    state: absent
    delegate_to: localhost
    run_once: true

 

Running this task should produce the following.

TASK [remove foo.txt on control node] 
changed: [server1.example.com -> localhost]

 



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 7777b in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |