0
問題出在subconfig1.vm.provision ...上,我應該如何繼續?初始化VM的Vagrant後,告訴我SSH工作正常,因爲連接被拒絕。我可以完成這項工作,但只能手動插入密碼,這裏我最大的問題是如何超越密碼來自動完成此工作流程。將文件從一臺虛擬機傳輸到另一臺虛擬機
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "Machine2" do |subconfig2|
subconfig2.vm.box = "ubuntu/trusty64"
subconfig2.vm.hostname = "Machine2"
subconfig2.vm.network :private_network, ip: "172.16.10.101"
subconfig2.vm.network "forwarded_port", guest: 80, host: 4445, host_ip: "127.0.0.1"
end
#config.vm.provision "file", source: "~/.vagrant/machines/Machine2/virtualbox/private_key", destination: "/home/vagrant/ssh"
config.vm.define "Machine1" do |subconfig1|
subconfig1.vm.box = "ubuntu/trusty64"
subconfig1.vm.hostname = "Machine1"
subconfig1.vm.network :private_network, ip: "172.16.10.100"
# subconfig1.vm.provision "file", source: "~/.vagrant/machines/Machine2/virtualbox/private_key", destination: "/home/vagrant"
subconfig1.vm.provision "shell", privileged: false, inline: <<-SHELL
touch vagrantvm1-info
ifconfig | grep "HWaddr" | cut -b 32-55 >> vagrantvm1-info
# ssh -o StrictHostKeyChecking=no [email protected] uptime
cp /vagrant/.vagrant/machines/Machine2/virtualbox/private_key ~/.ssh
scp -P 2222 -i ~/.ssh/private_key [email protected]:/home/vagrant/vagrantvm1-info /home/vagrant
# ssh [email protected]
# scp [email protected]:/home/vagrant/vagrantvm1-info /home/vagrant
SHELL
end
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
config.vm.provision "shell", privileged: false, inline: <<-SHELL
apt-get install -y avahi-daemon libnss-mdns
apt-get update
apt-get install -y apache2
SHELL
end
我修改了你告訴我的方式,現在唯一的問題是它沒有找到該文件:文件提供者: *文件上傳源文件C:/Users/Cristian/.vagrant/mac hines/Machine2/virtualbox/private_key必須存在 – Cristian
只需要'config.vm.provision「文件」,source:「.vagrant/machines/Machine2/virtualbox/private_key」,destination:「/ home/ssh」';並確保'private_key'存在於.vagrant/machines/Machine2/virtualbox/ –
如果我將此行標記出來並運行代碼,它可以工作,我使用vagrant ssh-configure,並且我可以在文件夾中看到私鑰,我甚至可以用帽子來裝飾它。但無論我將文件供應器放在vagrantfile的代碼中,我都無法訪問它,vagrant說該文件不存在。 – Cristian