title: How to get ip address from other host in ansible?
body: <p>I have vagrant configured with multiple machines and ansible:</p>
  
  <pre><code>config.vm.box = "ubuntu/trusty64"
  
  config.vm.define "my_server" do |my_server|
      my_server.vm.network "private_network", ip: "192.168.50.4"
  end
  
  config.vm.define "my_agent" do |my_agent|
      my_agent.vm.network "private_network", ip: "192.168.50.5"
  end
  
  config.vm.provision "ansible" do |ansible|
      ansible.groups = {
          "my-server" =&gt; ["my_server"],
          "my-agent" =&gt; ["my_agent"],
          "all_groups:children" =&gt; ["my-server", "my-agent"]
      }
      ansible.playbook = "./ansible/my.yml"
  end
  </code></pre>
  
  <p>And vagrant generate inventory file:</p>
  
  <pre><code># Generated by Vagrant
  
  my_server ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_private_key_file=/.../private_key
  my_agent ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_private_key_file=/.../private_key
  ...
  </code></pre>
  
  <p>When I run vagrant <code>my_server</code> gets ip:</p>
  
  <pre><code>eth0: 10.0.2.15
  eth1: 192.168.50.4
  </code></pre>
  
  <p>and <code>my_agent</code> gets ip:</p>
  
  <pre><code>eth0: 10.0.2.15
  eth1: 192.168.50.5
  </code></pre>
  
  <p>I want to add in agent configuration ip address of server (from eth1).
  I try debug informations about server:</p>
  
  <pre><code>- debug: var=hostvars[item]
    with_items: groups['my-server']
  </code></pre>
  
  <p>but i only gets: </p>
  
  <pre><code>ok: [my_agent] =&gt; (item=my_server) =&gt; {
      "item": "my_server", 
      "var": {
          "hostvars[item]": {
              "ansible_ssh_host": "127.0.0.1", 
              "ansible_ssh_port": 2222, 
              "ansible_ssh_private_key_file": ".../private_key", 
              "group_names": [
                  "all_groups", 
                  "my-server"
              ], 
              "inventory_hostname": "my_server", 
              "inventory_hostname_short": "my_server"
          }
      }
  }
  </code></pre>
  
  <p>Is it possible to get ip address of server in agent role? If it is possible how I can do it?</p>