title: Ansible - access var of another host
body: <p>I have this piece of the playbook.</p>
  <pre><code>- hosts: iperf_servers
    remote_user: root
    tasks:
    - name: print server iperf
      debug: msg=&quot;Starting Server Iperf with Data_IP &gt; {{ hostvars[inventory_hostname].nodes[0].data_ip }}&quot;
    - name: start server iperf
      shell: &quot;iperf3 -B {{ hostvars[inventory_hostname].nodes[0].data_ip }} --server --one-off --daemon&quot;
    - name: print friendly output
      debug: msg=&quot;Started Server IPERF On ip &gt; {{ hostvars[inventory_hostname].nodes[0].data_ip }}&quot;
  
  - hosts: iperf_clients
    remote_user: root
    tasks: 
    - name: print iperf server data_ip's from client
      debug: var=&quot;{ hostvars['groups']['iperf_servers'][0].data_ip }}&quot;
  </code></pre>
  <p>In the first play, with hosts 'iperf_servers' I'm accessing the var 'data_ip', which is stored inside host_vars, and this is how it looks:</p>
  <pre><code>---
  name: server00
  nodes:
  -   instanceID: 0
      data_ip: 200.100.1.150
  
  #** Note: under host_vars directory, I have 3 server files: **#
  
  'ls  light-app/ansible/inventories/cluster_example/host_vars/'
  
  server00.yml  server01.yml  server02.yml
  </code></pre>
  <p>As can be noticed, I'm accessing this var by:</p>
  <pre><code>{{ hostvars[inventory_hostname].nodes[0].data_ip }}
  </code></pre>
  <p>and it works just fine, I'm getting the value I'm expecting (the data_ip value) for each server file.</p>
  <p>What I need in the second play, is to access the same var, but while I'm running it on other hosts groups (iperf_clients).
  The idea is to get the data_ip of the servers and set it on the clients.
  So basically I'm trying to use the data_ip of another host.</p>
  <p>This way didn't work:</p>
  <pre><code>{{ hostvars['groups']['iperf_servers'][0].data_ip }}
  </code></pre>
  <p>I have tried so many ways and searched for so long. Is there a possible way to get these vars?</p>