首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对远程主机的Ansible ping在本地连接上有效,但在其他情况下不起作用

对远程主机的Ansible ping在本地连接上有效,但在其他情况下不起作用
EN

Stack Overflow用户
提问于 2016-07-15 16:41:14
回答 0查看 2.1K关注 0票数 1

我是一个彻头彻尾的新手,所以提前道歉!

我正在尝试运行一个Ansible剧本,它的作用是在我本地和远程机器上构建的程序之间实现文件共享/传输/同步(正如你可以猜到的,剧本不是我写的)。

我的问题是,当我不使用--connection=local时,我无法ping通远程主机。但是,我可以对远程主机执行ssh操作。当我运行playbook时,它抛出错误:

代码语言:javascript
复制
    host1 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh.", 
"unreachable": true}

如果我这样做了

代码语言:javascript
复制
    ansible-playbook cvfms.yml --connection=local

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

有关更多信息,请参阅我的/etc/ansible/hosts文件:

代码语言:javascript
复制
    [group_name]
    host1 ansible_ssh_host=lengau.chpc.ac.za

我还有一个/etc/ansible/host_var,表示我在机器上的用户名。

在这个问题上的任何帮助都将深表感谢!

作为对这些评论的回答:当我运行ansible-playbook -vvv cvfms.yml时,我得到了输出:

代码语言:javascript
复制
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“机器上,我现在有一个文件/home/testuser/.ssh/id_rsa,其中包含我通过

代码语言:javascript
复制
ssh-keygen -t rsa.

此私钥也存储在远程计算机上的/home/user/.ssh/目录中。

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

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

更奇怪的是,这一切只有在我是root用户的情况下才会发生。如果我是家庭计算机上的普通用户,则ssh运行正常,playbook在本地连接上运行,并显示新的错误消息,如下所示:

代码语言:javascript
复制
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 

我的本地机器上有严重的问题,我想...

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38391648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档