2015-10-20 45 views
0

我有一些问题,因为我无法在本地主机上ping服务器。我创建该文件的主机,这就是代码:ansible ping localhost

testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 \ ansible_ssh_user=vagrant \ ansible_ssh_private_key_file=.vagrant/machines/default/virtualbox/private_key 

我使用Fedora和我的虚拟化Debian中的VirtualBox 4.3

这就是附加在外壳:

[[email protected] ~]$ ansible testserver -i /home/andrea/playbooks/hosts -m ping -vvvv 
<127.0.0.1> ESTABLISH CONNECTION FOR USER: andrea 
<127.0.0.1> REMOTE_MODULE ping 
<127.0.0.1> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/home/andrea/.ansible/cp/ansible-ssh-%h-%p-%r" -o Port=2200 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 127.0.0.1 /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445357197.49-202989636750564 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1445357197.49-202989636750564 && echo $HOME/.ansible/tmp/ansible-tmp-1445357197.49-202989636750564' 
testserver | FAILED => SSH Error: Permission denied (publickey,password). 
    while connecting to 127.0.0.1:2200 
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue. 
+1

你首先需要做'SSH -i .vagrant /机/默认/ VirtualBox虚拟/ PRIVATE_KEY 127.0.0.1:2200'工作。您是否将Vagrant VM的ssh端口转发到主机上的端口2200?私密金钥是否在Vagrant嘉宾内正确设置? –

+0

如果我使用你的代码我得到登录屏幕。但是我创建了没有密码的机器,只有私钥 –

回答

1

我认为你是不要使用正确的用户/组合键登录。

尝试以下操作:

ansible -vvvv testserver -i /home/andrea/playbooks/hosts -m ping --private-key=.vagrant/machines/default/virtualbox/private_key -u vagrant 

我加

  • -u选项来指定用户(根据您发布它应该是流浪汉线)
  • - 私钥选项来告诉流浪汉在哪里可以找到你的ssh私钥文件

顺便说一句,如果你想登录你应该使用:

ssh -i .vagrant/machines/default/virtualbox/private_key [email protected] -p 2200 

(斯文忘了告诉你使用正确的用户,所以你可能试图登录使用“安德烈”用户)