2015-01-03 106 views
1

我剛開始使用Ansible和Vagrant。我在我的本地開發中安裝了Ansible,在我看來它運行良好。我在我的項目中創建無業遊民以這種方式清單文件:使用Ansible和Vagrant

vim inventory 
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 
ansible_ssh_user=vagrant 
ansible_ssh_private_key_file=/home/user/.vagrant.d/insecure_private_key 

蒙山使用下面我得到這個消息中提到的指令:

ansible testserver -i inventory -m ping 
testserver | FAILED => SSH encountered an unknown error during the connection. We  
recommend you re-run the command using -vvvv, which will enable SSH debugging output to  
help diagnose the issue 

什麼是配置ansible與流浪者的最佳方法是什麼? 此致敬意。

+1

重新運行'ansible'與'-vvvv'並添加輸出。 – tedder42

+1

我解決了這個問題:我不得不在同一行上發表聲明:testserver ansible_ssh_host = ip ansible_ssh_port = my_port ansible_ssh_private_key_file = my_file – sam

+1

請問您可以添加這個答案並接受它:我碰到過問題,並幾乎錯過了解決方案,因爲它在評論中 – Louis

回答

0

在Vagrant中,您可以使用Ansible插件,或者(如果不支持)回退到聯機供應商。這樣,您不需要在託管虛擬機的計算機上安裝Ansible。你Vagrantfile會是這個樣子:

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    config.vm.define "mybox" do |mybox| 
    mybox.vm.box = "ubuntu/trusty64" 
    mybox.vm.network "private_network", ip: "192.168.15.101" 
    mybox.vm.hostname = "mybox" 
    config.vm.provision "shell", 
     inline: "apt-get update && apt-get install python-software-properties -y && apt-get install software-properties-common -y && apt-add-repository ppa:ansible/ansible && apt-get update && apt-get install ansible -y && cp /vagrant/hosts /etc/ansible/hosts" 
    if Vagrant.has_plugin?("vagrant-ansible-local") 
     config.vm.provision "ansibleLocal", playbook: "playbook.yml" 
    else 
     config.vm.provision "shell", 
     inline: "ansible-playbook /vagrant/playbook.yml" 
    end 
    end 
end 

確保playbook.yml存在於同一目錄Vagrantfile。

  • vagrant up將啓動虛擬機,然後安裝Ansible +運行劇本
  • vagrant provision將重新運行劇本

此外,你可以做vagrant ssh,並從虛擬機中運行的劇本ansible-playbook /vagrant/playbook.yml

0

爲了防止有人遇到同樣的問題,解決方案只使用一條線,而不使用反斜槓。例如

TESTSERVER ansible_ssh_host = 127.0.0.1 ansible_ssh_port = 2222 ansible_ssh_user =流浪ansible_ssh_private_key_file = .vagrant /設備/默認/的virtualbox/PRIVATE_KEY