title: Ansible: How can I access a variable of other host?
body: <p>How can I access a variable of other host? I'd like to access the slack_token varaiable of my localhost on the working_host.</p>
  
  <pre><code>- hosts: localhost
    vars:
      slack_token: 123123123
    tasks:
      - block:
        - name: test
          debug: msg="{{ slack_token }}"
  
  - hosts: "{{ working_host }}"
    vars:
      slack_token: "{{ hostvars['localhost']['slack_token'] }}"                                                                                    
    tasks:
      - block:
        - name: test2
          debug: msg={{ slack_token }}
  </code></pre>
  
  <p>The error message:</p>
  
  <blockquote>
    <p>fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field
    'args' has an invalid value, which appears to include a variable that
    is undefined. The error was: {{ hostvars['localhost']['slack_token']
    }}: 'dict object' has no attribute 'slack_token'</p>
  </blockquote>
  
  <p>Any idea?</p>