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 pipe plugin, the Python pipe.py script must be in your Ansible plugins lookup directory, such as /usr/lib/python2.7/site-packages/ansible/plugins/lookup/pipe.py.
The lookup plugin can be used to return the hostname of your control node (your Ansible server). Let's say for example you have the following playbook.
---
- hosts: localhost
tasks:
- name: return control node hostname
debug:
msg: "{{ lookup('pipe', 'hostname') }}"
...
Running this playbook should return something like this. In this example, ansible.example.com is the hostname of the control node.
TASK [return control node hostname]
ok: [server1.example.com] => {
"msg: "ansible.example.com"
}
Or, there are a number of different magic variable will return the hostname of a managed node (e.g. the target systems).