title: Unable to get value of a variable from another Play in Ansible
body: <p>I wish to obtain the value of "fdet_APP" variable of Play 2 into Play 3.</p>
  
  <p>Below is my playbook which case be used as a testcase:</p>
  
  <pre><code>- name: "Play 1"
    hosts: localhost
    tasks:
     - add_host: name={{ item }}
                          groups=dest_nodes
                          ansible_user={{ USER }}
       with_items: "{{ Dest_IP.split(',') }}"
  
  - name: "Play 2"
    hosts: dest_nodes
    user: "{{ USER }}"
    tasks:
     - set_fact:
         fdet_APP: "Yellow"
  
  - name: "Play 3"
    hosts: localhost
    user: "{{ USER }}"
    vars:
      dbfiledet: "{{ hostvars['dest_nodes']['fdet_APP'] }}"
  
    tasks:
     - debug: msg="{{ dbfiledet.stdout }}"
  </code></pre>
  
  <p>I get the below error for my attempt:</p>
  
  <p>playbook RUN command: </p>
  
  <pre><code>ansible-playbook variabletest.yml -e "USER=user1 Dest_IP=10.17.44.26,10.17.54.26"
  </code></pre>
  
  <blockquote>
    <p>[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'</p>
    
    <p>PLAY [Play 1]</p>
    
    <hr>
    
    <p>TASK [Gathering Facts]
    ************************************************************************************************************************************** ok: [localhost]</p>
    
    <p>TASK [add_host]
    ********************************************************************************************************************************************* changed: [localhost] => (item=10.17.44.26) changed: [localhost] =>
    (item=10.17.54.26)</p>
    
    <p>PLAY [Play 2]</p>
    
    <hr>
    
    <p>TASK [Gathering Facts]
    ************************************************************************************************************************************** ok: [10.17.54.26] ok: [10.17.44.26]</p>
    
    <p>TASK [set_fact]
    ********************************************************************************************************************************************* ok: [10.17.44.26] ok: [10.17.54.26]</p>
    
    <p>PLAY [Play 3]</p>
    
    <hr>
    
    <p>TASK [Gathering Facts]
    ************************************************************************************************************************************** ok: [localhost]</p>
    
    <p>TASK [debug]
    ************************************************************************************************************************************************ fatal: [localhost]: FAILED! => {"msg": "The task includes an option
    with an undefined variable. The error was: \"hostvars['dest_nodes']\"
    is undefined\n\nThe error appears to be in 'variabletest.yml': line
    36, column 6, but may\nbe elsewhere in the file depending on the exact
    syntax problem.\n\nThe offending line appears to be:\n\n\n   - debug:
    msg=\"{{ dbfiledet.stdout }}\"\n     ^ here\nWe could be wrong, but
    this one looks like it might be an issue with\nmissing quotes. Always
    quote template expression brackets when they\nstart a value. For
    instance:\n\n    with_items:\n      - {{ foo }}\n\nShould be written
    as:\n\n    with_items:\n      - \"{{ foo }}\"\n"}</p>
    
    <p>PLAY RECAP</p>
    
    <hr>
    
    <p>10.17.44.26                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0<br>
    10.17.54.26                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0    localhost<br>
    : ok=3    changed=1    unreachable=0    failed=1    skipped=0<br>
    rescued=0    ignored=0</p>
  </blockquote>
  
  <p>I'm on the latest version of ansible and python 2.7.5</p>
  
  <p>Can someone suggest what is wrong and how can i get the value for the variable in Play 3 please ?</p>