Vagrant和Ansible Playbook中SSH连接主机失败

6

我找不到实际问题所在。我使用我的私钥执行了以下playbook:

---
- hosts: localhost
  gather_facts: false
  sudo: yes
  tasks:
    - name: Install package libpcre3-dev
      apt: name=libpcre3-dev state=latest

但是我在Vagrant Ubuntu机器上遇到了以下错误:
PLAY [localhost]   
*********************************************************************

TASK [Install package ] 
***************************************************
fatal: [vagrant]: UNREACHABLE! => {"changed": false, "msg": "Failed to
connect to the host via ssh: Permission denied (publickey,password).\r\n",
"unreachable": true}
        to retry, use: --limit @/home/vagrant/playbooks/p1.retry

PLAY RECAP
*********************************************************************
vagrant                    : ok=0    changed=0    unreachable=1    failed=0

可能的建议是什么?
1个回答

6
您正在使用SSH连接(Ansible的默认设置)运行针对本地主机localhost的playbook,但是失败了。很可能是因为您从未在计算机上配置帐户以接受来自自身的密钥。如果使用默认设置,您需要将~/.ssh/id_rsa.pub添加到~/.ssh/authorized_keys中。
相反,要在本地运行,请将connection:local添加到playbook中:
---
- hosts: localhost
  connection: local
  tasks:
    - debug:

它将会给你一个恰当的回应:

TASK [debug] *******************************************************************
ok: [localhost] => {
    "msg": "Hello world!"
}

1
没错。我在我的playbook中添加了connection:local行,现在它完美地工作了。谢谢..!!! - Tanay Suthar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接