对远程主机的Ansible ping可以在本地连接上工作,但不能

时间:2016-07-15 08:41:14

标签: ssh ansible

我是一个完整的Ansible新手,所以提前道歉!

我正在尝试运行一个Ansible手册,其作用是在本地和远程机器上构建的程序之间启用文件共享/传输/同步(正如你猜测的那样,我没有写剧本)。

我的问题是,当我不使用--connection = local时,我无法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-playbook -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   

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

在我的家中&#34;机器我现在有一个文件/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 

在我的本地机器上有些东西严重错误,我想......

1 个答案:

答案 0 :(得分:0)

我找到了答案!我觉得既高兴又愚蠢(脸红)......

问题是通过(执行上述所有步骤后)运行:

来解决的
ansible-playbook cvmfs.yml --ask-pass

在此之后它运行正常。

的输出
ansible all -m ping --ask-pass

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