ssh - Ansible 配置错误!无法使用 SSH 密码代替 key

标签 ssh vagrant ansible ansible-inventory

我想使用 Ansible 配置最后一个节点中的三个节点。

我的主机是Windows 10。

我的 Vagrantfile 看起来像:

Vagrant.configure("2") do |config|

  (1..3).each do |index|
    config.vm.define "node#{index}" do |node|

      node.vm.box = "ubuntu"
      node.vm.box = "../boxes/ubuntu_base.box"

      node.vm.network :private_network, ip: "192.168.10.#{10 + index}"

      if index == 3
        node.vm.provision :setup, type: :ansible_local do |ansible|
          ansible.playbook = "playbook.yml"
          ansible.provisioning_path = "/vagrant/ansible"
          ansible.inventory_path = "/vagrant/ansible/hosts"
          ansible.limit = :all
          ansible.install_mode = :pip
          ansible.version = "2.0"
        end
      end

    end
  end

end

我的剧本如下:

---

# my little playbook

- name: My little playbook
  hosts: webservers
  gather_facts: false
  roles:
    - create_user

我的主机文件如下所示:

[webservers]
192.168.10.11
192.168.10.12

[dbservers]
192.168.10.11
192.168.10.13

[all:vars]
ansible_connection=ssh
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant

执行vagrant up --provision后,出现以下错误:

Bringing machine 'node1' up with 'virtualbox' provider...
Bringing machine 'node2' up with 'virtualbox' provider...
Bringing machine 'node3' up with 'virtualbox' provider...
==> node3: Running provisioner: setup (ansible_local)...
    node3: Running ansible-playbook...

PLAY [My little playbook] ******************************************************

TASK [create_user : Create group] **********************************************
fatal: [192.168.10.11]: FAILED! => {"failed": true, "msg": "ERROR! Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}
fatal: [192.168.10.12]: FAILED! => {"failed": true, "msg": "ERROR! Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}

PLAY RECAP *********************************************************************
192.168.10.11              : ok=0    changed=0    unreachable=0    failed=1
192.168.10.12              : ok=0    changed=0    unreachable=0    failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

我使用 ansible.limit = :all 扩展了我的 Vagrantfile,并将 [all:vars] 添加到主机文件中,但仍然无法解决该错误。

有人遇到过同样的问题吗?

最佳答案

在项目目录中创建一个文件 ansible/ansible.cfg(即目标上 provisioning_path 中的 ansible.cfg),其中包含以下内容:

[defaults]
host_key_checking = false
<小时/>

假设您的 Vagrant 盒子已经安装了 sshpass - 目前还不清楚,因为您问题中的错误消息表明它已安装(否则将是“ERROR!使用带密码的“ssh”连接类型,您必须安装 sshpass 程序”),但在your answer您显式添加它(sudo apt-get install sshpass),就像它不是一样

关于ssh - Ansible 配置错误!无法使用 SSH 密码代替 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42462435/

相关文章:

mysql - 使用工作台通过 ssh 连接到远程 MySQL 数据库

ruby - Ubuntu - 从另一台计算机 Vagrant 访问

ansible - Jinja For Loop 中的重复行

linux - git post-receive 钩子(Hook),它通过 ssh 和 git pulls 连接到远程

git - git 中错误的配置选项

python - 导入 MySQLdb ImportError

Symfony 的 PhpStorm 和 Vagrant 的 Framework.ide 配置

git - ssh:连接到主机github.com端口22:将VM复制到另一台主机后,网络无法访问

git - 如何使用 Ansible 查看最近的 git 标签?

ansible - 检查数组是否已定义并且在ansible中不为空