Daily Archives: 04/09/2019

Ansible: get a target host’s IP

9 April 2019

 The task is to get a host’s IP during executing an Ansible task. Below – two examples of how this can be done. Example 1 – hostvars See the documentation here>>>. Code: – name: Test hosts list debug: msg: “{{ hostvars[inventory_hostname][‘ansible_default_ipv4’][‘address’] }}” Run it: Example 2 – lookup and dig Another approach could be using… Read More »