【发布时间】:2021-08-31 21:35:09
【问题描述】:
我试图在 Vagrantfile 中引用主机操作系统上的文件并设置环境变量。
但是,Vagrant 似乎无法找到该文件。
当引用与 Vagrantfile 位于同一目录中的文件时,一切正常。
1. Vagrantfile中Vagrant可以访问的文件是否仅限于VM目录?
2。是否可以在 Vagrantfile 中引用 VM 目录(test1、test2、test3...)之外的文件? (例如 /Users/hoge/vagrant/key.json)
我的项目和Vagrantfile如下。
/Users/hoge
/vagrant
- key.json
/test1
- Vagrantfile
- provision.sh
- /workspace
/test2
...
/test3
...
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/bionic64"
# Directory ./workspace needs to be made in advance, or error occurs.
config.vm.synced_folder "./workspace", "/home/vagrant/workspace"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# Customize the number of cpus on the VM:
vb.cpus = "2"
# Customize the amount of memory on the VM:
vb.memory = "2048"
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", path: "./provision.sh", env: {"CLIENT_SECRET" => "$(base64 /Users/hoge/vagrant/key.json)"}
end
主机操作系统:MacOS Big Sur 11.5.1
来宾操作系统:Ubuntu 18.04 LTS(ubuntu/bionic64)
流浪者 2.2.17
虚拟机 6.1.26
【问题讨论】:
标签: macos ubuntu vagrant vagrantfile