使用localhost进行ansible ping

时间:2015-10-20 16:16:57

标签: virtualbox ansible

我对ansible有一些问题,因为我无法在localhost中ping服务器。我创建了文件主机,这就是代码:

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,我使用virtualbox 4.3虚拟化Debian

这是shell中的附加内容:

[andrea@andrea ~]$ 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 个答案:

答案 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 vagrant@127.0.0.1 -p 2200

(Sven忘了告诉你使用正确的用户,所以你可能正在尝试使用&#34; andrea&#34;用户登录)