2017-02-25 190 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

相關問題