FreeKB - Ansible connection plugin
Ansible - connection plugin

By default, modules are run against your managed nodes (the target systems). The connection plugin with 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 connection plugin is used to run every task in the playbook against the control node.

---
- hosts: all
  connection: local
  tasks:
    - name: remove foo.txt on control node
        file:
        path: /tmp/foo.txt
        state: absent

 

Or, the --connection command line flag could be used.

ansible-playbook foo.yml --connection="local 127.0.0.1"

 

Often, run_once parameter is used so that each task in the playbook is only ran one time on the control node.

---
- hosts: all
  connection: local
  tasks:
    - name: remove foo.txt on control node
        file:
        path: /tmp/foo.txt
        state: absent
        run_once: true

 


Roles

All of the tasks in a particular role can be performed on the control node. In this example, every task in the "foo" role will be performed on the control node.

Or like this.

---
- hosts: all
  roles:
    - role: foo
      connection: local

 



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 6b239 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   |