2016-07-15 91 views
0

我是一个完整的Ansible新手,所以提前致歉!Ansible ping到远程主机在本地连接上工作,但没有其他

我试图运行一个Ansible playbook,它的作用是在本地和远程机器上构建的程序之间启用文件共享/传输/同步(正如您所猜测的,我没有编写剧本)。

我的问题是,我不能ping通远程主机,当我不使用 - 连接=本地。但是,我可以ssh远程主机。当我运行的剧本,它抛出的错误:

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

如果我做

ansible-playbook cvfms.yml --connection=local 

然后我没有得到ssh的错误,但是剧本不能做任何事情,因为我怀疑该连接应该不是本地运行。

欲了解更多信息,下面是我的/ etc/ansible/hosts文件:

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

我也有一个在/ etc/ansible/host_var,说我在机器的用户名。

对此问题的任何帮助将深表感谢!

在回答评论:当我运行ansible-剧本-vvv cvfms.yml,我得到的输出:

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 

在回答另一个问题: 我设置了这样的私钥:

在我的“家”的机器我现在有一个文件/home/testuser/.ssh/id_rsa,其中包含我通过

ssh-keygen -t rsa. 

获得的私钥这私钥也存储在远程机器上的/home/user/.ssh/目录中。

据我所知,这是正确的做法。

我仍然遇到与上面相同的问题,当我运行ansible-playbook或ping时。

并添加一些怪异的,所有这些只发生在我是根。如果我是一个普通用户我家的机器上,ssh的正常工作和剧本用新的错误消息在本地连接上如下运行,:

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 

也有一些是严重错误的东西在我的地方机器,我想...

+0

使用'-vvv'或'-vvvv'参数运行'ansible-playbook'来调试问题并将错误消息添加到您的问题中。 –

+0

您是否有适合您尝试连接的主机的SSH私钥文件? – activatedgeek

+0

非常感谢你们俩!我已经添加了必要的信息。我已经建立了私人密钥(我认为),并将有另一个去。 –

回答

0

我找到了答案!我感到既兴高采烈和非常愚蠢的(脸红)......

的问题是固定的(在做以上所有步骤后)的运行:

ansible-playbook cvmfs.yml --ask-pass 

这点之后运行良好。

ansible all -m ping --ask-pass 

在所有情况下都是“成功”,而不仅仅是在本地网络上。剧本运行良好。好极了!

相关问题