The lookup plugin is always executed on the control node (that's your Ansible server), which is to say that the lookup plugin does not do something on your managed nodes (the target systems).
To use the vars plugin, the Python vars.py script must be in your Ansible plugins lookup directory, such as /usr/lib/python2.7/site-packages/ansible/plugins/lookup/vars.py.
Let's say foo.yml contains the following. Notice the vars plugin is being used to create the "foo" variable.
---
- hosts: localhost
vars:
foo: bar
tasks:
- debug:
msg: "{{ lookup('vars', 'foo') }}"
...
Something like this should be returned.
TASK [debug]
ok: [localhost] => {
"msg": "bar"
}
One thing that is kind of unique and powerful about the lookup plugin is being able to search with multiple "parts" of a variable name.
---
- hosts: localhost
vars:
password_dev: devpw
password_prod: prodpw
tasks:
- debug:
msg: "{{ lookup('vars', 'password_' + 'dev' ) }}"
...
Or like this.
---
- hosts: localhost
vars:
password_dev: devpw
password_prod: prodpw
env: dev
tasks:
- debug:
msg: "{{ lookup('vars', 'password_' + env ) }}"
...
Which should return the following.
TASK [debug]
ok: [localhost] => {
"msg": "devpw"
}