2017-02-25 192 views
1

我想通过使用Ansible来配置最后一个节点的三个节点。Ansible provisioning错误!使用SSH密码而不是密钥是不可能的

我的主机是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 

我的hosts文件看起来像:

[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 

Af之三执行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. 

我伸出我的Vagrantfile与ansible.limit = :all并添加[all:vars]到HOSTFILE,但仍无法通过的错误提示。

有没有人遇到同样的问题?

回答

7

在您的项目目录中创建一个文件ansible/ansible.cfg(即ansible.cfg在目标上的provisioning_path)具有以下内容:

[defaults] 
host_key_checking = false 

前提是你的流浪箱已经安装sshpass - 目前还不清楚,因为在你的问题的错误消息表明,它被安装(否则这将是“错误!使用带有密码的“SSH”连接类型,您必须安装sshpass程序“),但在your answer你添加它明确(sudo apt-get install sshpass),就像是没有

+0

是的,这是有效的!不需要解决方法! – Mark

4

这个SO post给出了答案。

我只是延长了机器上的known_hosts文件,负责供应这样的:

从我的修改Vagrantfile段:

... 
if index == 3 
    node.vm.provision :pre, type: :shell, path: "install.sh" 

    node.vm.provision :setup, type: :ansible_local do |ansible| 
... 

我install.sh的样子:

# add web/database hosts to known_hosts (IP is defined in Vagrantfile) 
ssh-keyscan -H 192.168.10.11 >> /home/vagrant/.ssh/known_hosts 
ssh-keyscan -H 192.168.10.12 >> /home/vagrant/.ssh/known_hosts 
ssh-keyscan -H 192.168.10.13 >> /home/vagrant/.ssh/known_hosts 
chown vagrant:vagrant /home/vagrant/.ssh/known_hosts 

# reload ssh in order to load the known hosts 
/etc/init.d/ssh reload 
+1

shellscripting解决方法。Ansible确保更好的办法,但! – Mark

相关问题