2016-05-28 80 views
0

我有3臺機器和Ansible作爲服務器提供程序的簡單Vagrantfile。 Vagrantfile看起來是這樣的:Ansible只能提供多機器中的第一臺機器Vagrantfile

# -*- mode: ruby -*- 
# vi: set ft=ruby : 
Vagrant.configure(2) do |config| 

# Jira machine 
config.vm.define 'jira' do |jira| 
    jira.vm.box = 'puppetlabs/ubuntu-14.04-64-nocm' 
    jira.vm.network "private_network", ip:"192.168.77.11" 
    jira.vm.hostname = 'jira' 
    jira.vm.provider :virtualbox do |vb| 
    vb.name = 'jira' 
    end 
end 

# Master machine with proxy beetwen mattermost and jira 
config.vm.define 'master' do |master| 
    master.vm.box = 'puppetlabs/ubuntu-14.04-64-nocm' 
    master.vm.network "private_network", ip:"192.168.77.10" 
    master.vm.hostname = 'master' 
    master.vm.provider :virtualbox do |vb| 
    vb.name = 'master' 
    end 
end 

# Mattermost machine 
config.vm.define 'mattermost' do |mattermost| 
    mattermost.vm.box = 'puppetlabs/ubuntu-14.04-64-nocm' 
    mattermost.vm.network "private_network", ip:"192.168.77.12" 
    mattermost.vm.hostname = 'mattermost' 
    mattermost.vm.provider :virtualbox do |vb| 
    vb.name = 'mattermost' 
    end 
end 

# Provision part 
config.vm.provision :ansible do |ansible| 
    ansible.limit = 'all' 
    ansible.playbook = 'provisioning/main.yml' 
    ansible.inventory_path = 'developer' 
    ansible.sudo = true 
    ansible.verbose = '-vvvv' 
end 

無業遊民了,名單上的第一臺機器被正確配置後,但後來Ansible不能ssh到下一個。正如我在調試中看到的,它仍然使用相同的私鑰對其餘機器進行身份驗證。以下是提供產出的要點:https://gist.github.com/Cosaquee/224a84f171aa8cd458d9ce56e8c8e111

我剛開始玩Ansible,所以我不知道如何強制使用私人密鑰每臺機器不只是一個。也許問題出在別的什麼地方。

任何幫助將是很好的。謝謝。

+0

你可以在每個機器塊中運行可靠的配置嗎?我知道這是重複的代碼,所以不太好,但要看看它是否有效 - 如果它以這種方式工作,則可能需要針對流浪漢創建一張票 –

回答

1

這就是你的配置應該看起來像什麼。注意配置器如何嵌套

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 

    # Webserver, jobserver and message queue VM 
    config.vm.define "app", primary: true do |app| 

     app.vm.box = "ubuntu/trusty64" 
     app.vm.hostname = "app.restream.vm" 
     app.vm.synced_folder ".", "/vagrant", disabled: true 
     app.vm.synced_folder ".", "/var/www/app" 
     app.vm.synced_folder "../infra", "/var/www/infra" 
     app.vm.synced_folder "../widgetcodebucket", "/var/www/widgetcodebucket" 
     app.vm.network "private_network", ip: "10.10.10.90" 

     app.vm.provider "virtualbox" do |vb| 
      vb.gui = false 
      vb.customize ["modifyvm", :id, "--nictype1", "virtio"] 
      vb.customize ["modifyvm", :id, "--memory", "4096"] 
      vb.customize ["modifyvm", :id, "--cpus", "4"] 
     end 

     app.vm.provision "ansible" do |ansible| 
      ansible.host_key_checking = false 
      ansible.limit = 'all' 
      #ansible.verbose = 'vvvv' 
      ansible.inventory_path = '../infra/hosts-dev' 
      ansible.playbook = "../infra/vm.yml" 
      ansible.extra_vars = { 
       symfony_env: 'dev', 
       ansible_ssh_user: 'vagrant', 
       nginx_user: 'vagrant', 
       redis_ip: '127.0.0.1', 
       redis_port: 6379, 
       git_branch: "develop" 
      } 
     end 
    end 

    # Statistics and monitoring VM 
    config.vm.define "stats" do |stats| 
     stats.vm.box = "ubuntu/trusty64" 
     stats.vm.hostname = "stats.restream.vm" 
     stats.vm.synced_folder ".", "/vagrant", disabled: true 
     stats.vm.synced_folder "../infra", "/var/www/infra" 
     stats.vm.network "private_network", ip: "10.10.11.11" 

     stats.vm.provider "virtualbox" do |vb| 
      vb.gui = false 
      vb.customize ["modifyvm", :id, "--nictype1", "virtio"] 
      vb.customize ["modifyvm", :id, "--memory", "4096"] 
      vb.customize ["modifyvm", :id, "--cpus", "4"] 
     end 

     stats.vm.provision "ansible" do |ansible| 
      ansible.limit = 'all' 
      ansible.host_key_checking = false 
      #ansible.verbose = 'vvvv' 
      ansible.inventory_path = '../infra/hosts-dev' 
      ansible.playbook = "../infra/stats.yml" 
      ansible.extra_vars = { 
       symfony_env: 'dev', 
       ansible_ssh_user: 'vagrant', 
       graphite_db_name: 'graphite', 
       graphite_db_engine: 'django.db.backends.mysql', 
       graphite_db_user: 'root', 
       graphite_db_pass: 'root', 
       graphite_db_host: '127.0.0.1', 
       graphite_db_port: 3306 
      } 
     end 
    end 

end 
相關問題