title: Ansible ping to remote host works on local connection but not otherwise
body: <p>I am a complete Ansible newbie, so apologies in advance! </p>
  
  <p>I am trying to run an Ansible playbook whose role is to enable file sharing/transfer/synchronicity between programs I build locally and on a remote machine (as you can guess, I didn't write the playbook). </p>
  
  <p>My issue is that I cannot ping the remote host when I don't use --connection=local. I can, however, ssh the remote host. When I run the playbook, it throws the error:</p>
  
  <pre><code>    host1 | UNREACHABLE! =&gt; {
  "changed": false, 
  "msg": "Failed to connect to the host via ssh.", 
  "unreachable": true}
  </code></pre>
  
  <p>If I do </p>
  
  <pre><code>    ansible-playbook cvfms.yml --connection=local
  </code></pre>
  
  <p>then I don't get the ssh error, but the playbook can't do anything, since I suspect the connection should be other than local for it to run.     </p>
  
  <p>For further information, here is my /etc/ansible/hosts file:</p>
  
  <pre><code>    [group_name]
      host1 ansible_ssh_host=lengau.chpc.ac.za
  </code></pre>
  
  <p>I also have a /etc/ansible/host_var, saying my username at the machine.</p>
  
  <p>Any help on this issue would be deeply appreciated!</p>
  
  <p>In answer to the comments: when I run ansible-playbook -vvv cvfms.yml, I get the output:</p>
  
  <pre><code>PLAYBOOK: cvmfs.yml     ************************************************************
  2 plays in /home/testuser/Documents/DevOps-master/Ansible/cvmfs.yml
  
  PLAY [Enable CVMFS]  ************************************************************
  
  TASK [setup] *******************************************************************
  Using module file /usr/lib/python2.6/site-packages/ansible-2.2.0-    py2.6.egg/ansible/modules/core/system/setup.py
  &lt;lengau.chpc.ac.za&gt; ESTABLISH SSH CONNECTION FOR USER: khenninger
  &lt;lengau.chpc.ac.za&gt; SSH: EXEC ssh -q -C -o ControlMaster=auto -o     ControlPersist=60s -o 'IdentityFile="/home/testuser/.ssh/id_rsa"' -o     KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o   User=khenninger -o ConnectTimeout=10 -o   ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r lengau.chpc.ac.za  '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo  $HOME/.ansible/tmp/ansible-tmp-1468582573.96-15730857177484 `" &amp;&amp; echo  ansible-tmp-1468582573.96-15730857177484="` echo  $HOME/.ansible/tmp/ansible-tmp-1468582573.96-15730857177484 `" ) &amp;&amp; sleep  0'"'"''
  fatal: [host1]: UNREACHABLE! =&gt; {"changed": false, "msg": "Failed to     connect to the host via ssh.", "unreachable": true}
  to retry, use: --limit @/home/testuser/Documents/DevOps-  master/Ansible/cvmfs.retry
  
  PLAY RECAP *********************************************************************
  host1                      : ok=0    changed=0    unreachable=1    failed=0   
  </code></pre>
  
  <p>In response to the other question:
  I set up the private keys like this:</p>
  
  <p>On my "home" machine I now have a file /home/testuser/.ssh/id_rsa, which contains the private key I obtained via </p>
  
  <pre><code>ssh-keygen -t rsa.
  </code></pre>
  
  <p>This private key is stored in the directory /home/user/.ssh/ on the remote machine as well. </p>
  
  <p>As far as I can gather, that was the right thing to do. </p>
  
  <p>I still get the same issues as above when I run ansible-playbook or when I ping. </p>
  
  <p>And to add some weirdness, all of this only happens if I am root. If I am a normal user on my home machine, the ssh works fine, and the playbook runs on the local connection with a new error message, as below:</p>
  
  <pre><code>ansible-playbook cvmfs.yml --connection=local
  
  PLAY [Enable CVMFS]     ************************************************************
  
  TASK [setup] *******************************************************************
  ok: [196.24.44.83]
  ok: [host1]
  
  TASK [Inform the team] *********************************************************
  fatal: [host1]: FAILED! =&gt; {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'slack_token' is undefined\n\nThe error appears to have been in '/home/testuser/Documents/DevOps-master/Ansible/cvmfs.yml': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  pre_tasks:\n    - name: Inform the team\n      ^ here\n"}
  fatal: [196.24.44.83]: FAILED! =&gt; {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'slack_token' is undefined\n\nThe error appears to have been in '/home/testuser/Documents/DevOps-master/Ansible/cvmfs.yml': line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  pre_tasks:\n    - name: Inform the team\n      ^ here\n"}
  
  NO MORE HOSTS LEFT *************************************************************
      to retry, use: --limit @cvmfs.retry
  
  PLAY RECAP *********************************************************************
  196.24.44.83               : ok=1    changed=0    unreachable=0    failed=1   
  host1                      : ok=1    changed=0    unreachable=0    failed=1 
  </code></pre>
  
  <p>There is something seriously wrong with something on my local machine, I think...</p>