Ansible - lookup pipe hostname (control node)

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 script must be in your Ansible plugins lookup directory, such as /usr/lib/python2.7/site-packages/ansible/plugins/lookup/

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
    - name: return control node hostname
        msg: "{{ lookup('pipe', 'hostname') }}"


Running this playbook should return something like this. In this example, is the hostname of the control node.

TASK [return control node hostname]
ok: [] => {
    "msg: ""


Or, there are a number of different magic variable will return the hostname of a managed node (e.g. the target systems).


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


Web design by yours truely - me, myself, and I   |   |