In Ansible, there are three types of Special Variables.
- Connection Variables (this article)
- Magic Variables
- Facts
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.
---
- hosts: all
roles:
- role: foo
connection: local
Did you find this article helpful?
If so, consider buying me a coffee over at