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 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).

 



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.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |