2015-10-20 63 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 

(斯文忘了告訴你使用正確的用戶,所以你可能試圖登錄使用「安德烈」用戶)