我们的vagrant设置包含一个Vagrant文件,该文件在vm置备时安装了一些软件。 为此,我们拥有要安装的软件档案和一些安装技巧。 这些软件档案和安装脚本目录中,我们正在同步流浪文件。 安装完成后,Vagrant文件将具有一个触发器,可以使软件存档和安装脚本目录不同步。 调用此触发器时,我们将不同步/ vagrant目录以及我们的软件档案和安装脚本目录。
/ vagrant目录成功取消同步,但是软件存档和 安装脚本目录未同步。
我怀疑,我同步软件档案和安装脚本目录的方式不正确。请建议如何正确地使软件档案和安装脚本目录不同步。
请在下面找到简化的Vagrantfile和供应外壳脚本:-
Vagrantfile:-
SOFTWARES_DIR = "/Users/dev/bundles/softwares"
Vagrant.configure("2") do |config|
config.vm.define "sampleMachine" do |sm|
#trigger that will unsync /vagrant and /softwares directory
sm.trigger.after :up do |trigger|
trigger.name = "Unsync script"
trigger.info = "Unsyncing /vagrant, /softwares directory"
#unsyncing of /vagrant directory working fine
sm.vm.synced_folder ".", "/vagrant", disabled: true
#unsyncing previously synced /softwares directory, once the installation of softwares is done
#but it's not unsyncing
sm.vm.synced_folder "#{SOFTWARES_DIR}", "/softwares", disabled: true
end
sm.vm.box = "centos/7"
sm.vm.hostname = "machineWithUnsyncedFolders"
sm.vm.network "private_network", ip: "192.168.33.191"
#folders synced for installing softwares at the time of machine provisioning
#is there any alternate way of syncing, so that unsycing works
sm.vm.synced_folder "#{SOFTWARES_DIR}", "/softwares", id: "softwares", :nfs => true, :mount_options => ['nolock,vers=3,udp,noatime']
#this script will use files that are synced in above statement for installing softwares
sm.vm.provision "shell", path: "script.sh"
end
end
script.sh:-
echo "provisioning vm for development setup"
function installSoftwares(){
local MACHINE_NAME=`hostname`
echo "machine name is >$MACHINE_NAME<, installing below softwares :-"
ls -1 /softwares
}
installSoftwares
当目录在根目录中列出时,vagrant目录不存在,但是softwares目录仍然存在,这意味着它在Vagrant文件触发器中并未取消同步。
请在vm的根目录中找到以下目录列表:-
vagrant ssh
[vagrant@machineWithUnsyncedFolders ~]$ cd /
[vagrant@machineWithUnsyncedFolders /]$ ls -1
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
softwares
srv
sys
tmp
usr
var
[vagrant@machineWithUnsyncedFolders /]$
请在下面找到流浪者日志:-
~/othervms/vagrantExamples/vbProvider/removeSyncedFolderAfterUse $
ls -a
. .. Vagrantfile script.sh
~/othervms/vagrantExamples/vbProvider/removeSyncedFolderAfterUse $
vagrant up
Bringing machine 'sampleMachine' up with 'virtualbox' provider...
==> sampleMachine: Importing base box 'centos/7'...
==> sampleMachine: Matching MAC address for NAT networking...
==> sampleMachine: Checking if box 'centos/7' version '1804.02' is up to date...
==> sampleMachine: Setting the name of the VM: removeSyncedFolderAfterUse_sampleMachine_1553489790050_21418
==> sampleMachine: Fixed port collision for 22 => 2222. Now on port 2200.
==> sampleMachine: Clearing any previously set network interfaces...
==> sampleMachine: Preparing network interfaces based on configuration...
sampleMachine: Adapter 1: nat
sampleMachine: Adapter 2: hostonly
==> sampleMachine: Forwarding ports...
sampleMachine: 22 (guest) => 2200 (host) (adapter 1)
==> sampleMachine: Booting VM...
==> sampleMachine: Waiting for machine to boot. This may take a few minutes...
sampleMachine: SSH address: 127.0.0.1:2200
sampleMachine: SSH username: vagrant
sampleMachine: SSH auth method: private key
sampleMachine:
sampleMachine: Vagrant insecure key detected. Vagrant will automatically replace
sampleMachine: this with a newly generated keypair for better security.
sampleMachine:
sampleMachine: Inserting generated public key within guest...
sampleMachine: Removing insecure key from the guest if it's present...
sampleMachine: Key inserted! Disconnecting and reconnecting using new SSH key...
==> sampleMachine: Machine booted and ready!
==> sampleMachine: Checking for guest additions in VM...
sampleMachine: No guest additions were detected on the base box for this VM! Guest
sampleMachine: additions are required for forwarded ports, shared folders, host only
sampleMachine: networking, and more. If SSH fails on this machine, please install
sampleMachine: the guest additions and repackage the box to continue.
sampleMachine:
sampleMachine: This is not an error message; everything may continue to work properly,
sampleMachine: in which case you may ignore this message.
==> sampleMachine: Setting hostname...
==> sampleMachine: Configuring and enabling network interfaces...
==> sampleMachine: Exporting NFS shared folders...
==> sampleMachine: Preparing to edit /etc/exports. Administrator privileges will be required...
The nfsd service does not appear to be running.
Starting the nfsd service
==> sampleMachine: Mounting NFS shared folders...
==> sampleMachine: Running provisioner: shell...
sampleMachine: Running: /var/folders/3y/zgjk378n4r968pv_q095ttkh0000gn/T/vagrant-shell20190325-42456-bm7v10.sh
sampleMachine: provisioning vm for development setup
sampleMachine: machine name is >machineWithUnsyncedFolders<, installing below softwares :-
sampleMachine: apache-hive-1.1.0-bin.tar.gz
sampleMachine: apache-hive-1.2.2-bin.tar.gz
sampleMachine: apache-hive-2.1.1-bin.tar.gz
sampleMachine: apache-hive-2.3.3-bin.tar.gz
sampleMachine: apache-hive-3.1.0-bin.tar.gz
sampleMachine: apache-maven-3.6.0-bin.tar.gz
sampleMachine: apache-tomcat-7.0.90.tar.gz
sampleMachine: hadoop-2.6.0.tar.gz
sampleMachine: hadoop-2.8.4.tar.gz
sampleMachine: hadoop-2.9.0.tar.gz
sampleMachine: jdk-8u171-linux-x64.tar.gz
sampleMachine: mysql-connector-java-5.1.47.tar.gz
sampleMachine: scala-2.11.12.tgz
sampleMachine: spark-2.3.1-bin-hadoop2.7.tgz
sampleMachine: spark-2.4.0-bin-hadoop2.7.tgz
==> sampleMachine: Running action triggers after up ...
==> sampleMachine: Running trigger: Unsync script...
==> sampleMachine: Unsyncing /vagrant, /softwares directory
~/othervms/vagrantExamples/vbProvider/removeSyncedFolderAfterUse $
vagrant ssh
[vagrant@machineWithUnsyncedFolders ~]$ whoami
vagrant
[vagrant@machineWithUnsyncedFolders ~]$ hostname
machineWithUnsyncedFolders
[vagrant@machineWithUnsyncedFolders ~]$ pwd
/home/vagrant
[vagrant@machineWithUnsyncedFolders ~]$ cd /
[vagrant@machineWithUnsyncedFolders /]$ pwd
/
[vagrant@machineWithUnsyncedFolders /]$ ls -1
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
softwares
srv
sys
tmp
usr
var
[vagrant@machineWithUnsyncedFolders /]$
如何正确取消自定义文件夹的同步。