KR_Henninger
KR_Henninger

Reputation: 107

Ansible ping to remote host works on local connection but not otherwise

I am a complete Ansible newbie, so apologies in advance!

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).

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:

    host1 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh.", 
"unreachable": true}

If I do

    ansible-playbook cvfms.yml --connection=local

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.

For further information, here is my /etc/ansible/hosts file:

    [group_name]
    host1 ansible_ssh_host=lengau.chpc.ac.za

I also have a /etc/ansible/host_var, saying my username at the machine.

Any help on this issue would be deeply appreciated!

In answer to the comments: when I run ansible-playbook -vvv cvfms.yml, I get the output:

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
<lengau.chpc.ac.za> ESTABLISH SSH CONNECTION FOR USER: khenninger
<lengau.chpc.ac.za> 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 && mkdir -p "` echo  $HOME/.ansible/tmp/ansible-tmp-1468582573.96-15730857177484 `" && echo  ansible-tmp-1468582573.96-15730857177484="` echo  $HOME/.ansible/tmp/ansible-tmp-1468582573.96-15730857177484 `" ) && sleep  0'"'"''
fatal: [host1]: UNREACHABLE! => {"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   

In response to the other question: I set up the private keys like this:

On my "home" machine I now have a file /home/testuser/.ssh/id_rsa, which contains the private key I obtained via

ssh-keygen -t rsa.

This private key is stored in the directory /home/user/.ssh/ on the remote machine as well.

As far as I can gather, that was the right thing to do.

I still get the same issues as above when I run ansible-playbook or when I ping.

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:

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! => {"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! => {"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 

There is something seriously wrong with something on my local machine, I think...

Upvotes: 1

Views: 3126

Answers (1)

KR_Henninger
KR_Henninger

Reputation: 107

I found the answer! I feel both elated and very dumb (blush)...

The problem was fixed by (after doing all the steps above) running:

ansible-playbook cvmfs.yml --ask-pass

After which point it runs fine. The output of

ansible all -m ping --ask-pass

was then "success" in all cases, not just over the local network. And the playbook runs fine. Yay!

Upvotes: 1

Related Questions