vagrant unsync文件夹不适用于自定义目录

vagrant unsync文件夹不适用于自定义目录,vagrant,vagrant-provision,Vagrant,Vagrant Provision,我们的vagrant安装程序包括一个vagrant文件,在vm配置时安装一些软件。 为此,我们有要安装的软件档案和一些安装技巧。 这些软件档案和安装脚本的目录,我们正在同步的流浪文件。 安装完成后,Vagrant文件将触发unsync软件归档和安装脚本目录。 调用此触发器时,我们将取消同步/vagrant目录以及软件归档和安装脚本目录 /流浪目录不同步成功,但软件存档和 安装脚本目录未取消同步 我怀疑,我同步软件存档和安装脚本目录的方式不正确。请建议如何正确地取消同步软件存档和安装脚本目录 请

我们的vagrant安装程序包括一个vagrant文件,在vm配置时安装一些软件。 为此,我们有要安装的软件档案和一些安装技巧。 这些软件档案和安装脚本的目录,我们正在同步的流浪文件。 安装完成后,Vagrant文件将触发unsync软件归档和安装脚本目录。 调用此触发器时,我们将取消同步/vagrant目录以及软件归档和安装脚本目录

/流浪目录不同步成功,但软件存档和 安装脚本目录未取消同步

我怀疑,我同步软件存档和安装脚本目录的方式不正确。请建议如何正确地取消同步软件存档和安装脚本目录


请查找以下简化的文件和配置shell脚本:-

流浪者文件:-

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
请查看以下流浪者日志:-

~/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 /]$
~/othervms/vagrantExamples/vbProvider/removeSyncedFolderAfterUse$
ls-a
.       ..      Vagrantfile script.sh
~/othervms/vagrantExamples/vbProvider/removeSyncedFolderAfterUse$
流浪汉
正在将计算机“sampleMachine”与“virtualbox”提供程序联系起来。。。
==>sampleMachine:正在导入基本框“centos/7”。。。
==>sampleMachine:匹配NAT网络的MAC地址。。。
==>sampleMachine:正在检查框“centos/7”版本“1804.02”是否为最新版本。。。
==>sampleMachine:设置VM的名称:removeSyncedFolderAfterUse\u sampleMachine\u 1553489790050\u 21418
==>sampleMachine:修复了22=>2222的端口冲突。现在在2200端口。
==>sampleMachine:清除以前设置的任何网络接口。。。
==>sampleMachine:根据配置准备网络接口。。。
样本机:适配器1:nat
sampleMachine:适配器2:仅主机
==>sampleMachine:转发端口。。。
样本机:22(来宾)=>2200(主机)(适配器1)
==>sampleMachine:正在引导VM。。。
==>sampleMachine:正在等待机器启动。这可能需要几分钟。。。
sampleMachine:SSH地址:127.0.0.1:2200
sampleMachine:SSH用户名:vagrant
sampleMachine:SSH身份验证方法:私钥
取样机:
sampleMachine:检测到流浪不安全密钥。流浪汉将自动替换
sampleMachine:这是一个新生成的密钥对,具有更好的安全性。
取样机:
sampleMachine:正在来宾中插入生成的公钥。。。
sampleMachine:正在从来宾删除不安全的密钥(如果存在的话)。。。
取样机:钥匙插入!正在使用新SSH密钥断开和重新连接。。。
==>sampleMachine:机器已启动并准备就绪!
==>sampleMachine:正在VM中检查来宾添加。。。
sampleMachine:在此VM的基本框上未检测到来宾添加!客人
sampleMachine:转发端口、共享文件夹、仅主机需要添加
sampleMachine:网络等。如果SSH在此计算机上失败,请安装
sampleMachine:客户添加并重新包装箱子以继续。
取样机:
sampleMachine:这不是错误消息;一切可能继续正常运行,
sampleMachine:在这种情况下,您可以忽略此消息。
==>sampleMachine:正在设置主机名。。。
==>sampleMachine:配置和启用网络接口。。。
==>sampleMachine:正在导出NFS共享文件夹。。。
==>sampleMachine:准备编辑/etc/exports。需要管理员权限。。。
nfsd服务似乎未运行。
启动nfsd服务
==>sampleMachine:正在装载NFS共享文件夹。。。
==>sampleMachine:正在运行provisioner:shell。。。
样本机:运行:/var/folders/3y/zgjk378n4r968pv_q095ttkh0000gn/T/vagrant-shell20190325-42456-bm7v10.sh
sampleMachine:为开发设置设置虚拟机
sampleMachine:计算机名称为>machineWithUnsyncedFolders sampleMachine:启动后运行操作触发器。。。
==>sampleMachine:正在运行触发器:不同步脚本。。。
==>sampleMachine:Unsyncing/vagrant,/softwares目录
~/othervms/vagrantExamples/vbProvider/removeSyncedFolderAfterUse$
流浪汉
[vagrant@machineWithUnsyncedFolders~]$whoami
流浪汉
[vagrant@machineWithUnsyncedFolders~]$hostname
machineWithUnsyncedFolders
[vagrant@machineWithUnsyncedFolders~]$pwd
/家庭/流浪者
[vagrant@machineWithUnsyncedFolders~]$cd/
[vagrant@machineWithUnsyncedFolders/]$pwd
/
[vagrant@machineWithUnsyncedFolders/]$ls-1
箱子
靴子
发展
等
家
解放党
lib64
媒体
mnt
选择
过程
根
跑
斯宾
软件
srv
系统
tmp
usr
变量
[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 /]$