title: ansible and access to the variable
body: <p>I have tow server. I execute this command.</p>
  
  <pre><code>- name: get vars
    shell: cat myfile
    register: result
  </code></pre>
  
  <p>On this server, I have access to the variable with <code>debug: msg=result.stdout</code></p>
  
  <p>but I want to access <code>result.stdout</code> on another server! is it possible?</p>
  
  <p><strong>Edite -1</strong></p>
  
  <p>my hosts file: </p>
  
  <pre><code>[master-slave]
  192.168.231.102 role=master
  192.168.231.92 role=slave
  [master]
  192.168.231.102
  </code></pre>
  
  <p>my task is :</p>
  
  <pre><code>- name: --------get Position ------------
    shell: echo "SHOW MASTER STATUS\G;" | mysql -u root | cut -d ":" -f 2 | grep -v \* | grep -v bin | tr -d " \t\n\r" 
    register: rep_position
  - set_fact: 
     rep_pos: "{{ rep_position }}"
    when: role == "master"
  
  
  - name: -----------From  Master -------------
    debug: msg="{{ rep_pos.stdout }}"  
    when: role == "master"
  
  - name: ---------- From Slave --------------------------------------
    debug: msg="{{hostvars[master].rep_pos.stdout}}"  
    when: role == "slave"
    ignore_errors: true
  </code></pre>
  
  <p>output is : </p>
  
  <pre><code>TASK [Master_Node_Galera : -----------From  Master ----------] *******************************************************************
  skipping: [192.168.231.92]
  ok: [192.168.231.102] =&gt; {
      "msg": "638"
  }
  
  TASK [Master_Node_Galera : ---------- From Slave ---------------------] ***********************************************
  skipping: [192.168.231.102]
  fatal: [192.168.231.92]: FAILED! =&gt; {"msg": "The task includes an option with an undefined variable. The error was: 'master' is undefined\n\nThe error appears to have been in '/etc/ansible/roles/Master_Node_Galera/tasks/main.yml': line 62, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: ---------- From Slave --------------------------------------\n  ^ here\n\nexception type: &lt;class 'ansible.errors.AnsibleUndefinedVariable'&gt;\nexception: 'master' is undefined"}
  ...ignoring
  </code></pre>
  
  <p>i get error !</p>
  
  <p><strong>Edit -2</strong></p>
  
  <p>I tested it, only with ip is worked.</p>
  
  <pre><code>- name: ---------- From Slave --------------------------------------
    debug: msg="{{hostvars['master'].rep_pos.stdout}}"  
    when: role == "slave"
    ignore_errors: true
  </code></pre>
  
  <p>output : </p>
  
  <pre><code>TASK [Master_Node_Galera : ---------- From Slave ---------------] **********************************************
  skipping: [192.168.231.102]
  fatal: [192.168.231.92]: FAILED! =&gt; {"msg": "The task includes an option with an undefined variable. The error was: \"hostvars['master']\" is undefined\n\nThe error appears to have been in '/etc/ansible/roles/Master_Node_Galera/tasks/main.yml': line 62, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: ---------- From Slave --------------------------------------\n  ^ here\n\nexception type: &lt;class 'ansible.errors.AnsibleUndefinedVariable'&gt;\nexception: \"hostvars['master']\" is undefined"}
  ...ignoring
  </code></pre>
  
  <p><strong>ip check</strong></p>
  
  <pre><code>- name: ---------- From Slave --------------------------------------
    debug: msg="{{hostvars['192.168.231.102'].rep_pos.stdout}}"  
    when: role == "slave"
    ignore_errors: true
  </code></pre>
  
  <p>Output : </p>
  
  <pre><code>TASK [Master_Node_Galera : ---------- From Slave-----------] ******************************************************
  skipping: [192.168.231.102]
  ok: [192.168.231.92] =&gt; {
      "msg": "638"
  }
  </code></pre>