Vagrant 手册之 Provisioning - file 配置程序
Provisioner 命令:“file”
通过 file 配置程序可以上传宿主机的文件或目录到虚拟机中。
使用场景:将宿主机的 ~/.gitconfig 复制到虚拟机中的用户家目录,这样就不用每次都要为新的虚拟机执行 git config --global:
Vagrant.configure("2") do |config|
# ... other configuration
config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
end
可以上传目录到虚拟机。复制时,宿主机上的文件夹将替换文件夹作为新文件夹并将其放在虚拟机上。注意,如果希望在虚拟机上使用相同的文件夹名称,请确保目标路径(destination )与主机上的文件夹名称相同。
Vagrant.configure("2") do |config|
# ... other configuration
config.vm.provision "file", source: "~/path/to/host/folder", destination: "$HOME/remote/newfolder"
end
在将 ~/path/to/host/folder 复制到虚拟机之前:
folder
├── script.sh
├── otherfolder
│ └── hello.sh
├── goodbye.sh
├── hello.sh
└── woot.sh
1 directory, 5 files
将 ~/path/to/host/folder 复制到虚拟机中的 $HOME/remote/newfolder 之后:
newfolder
├── script.sh
├── otherfolder
│ └── hello.sh
├── goodbye.sh
├── hello.sh
└── woot.sh
1 directory, 5 files
注意,与同步文件夹不同,上传的文件或目录不会保持同步。对于上面的例子,如果对本地 ~/.gitconfig 进行更改,它们将不会立即反映在上传到虚拟机的副本中。
由 file provisioner 上传的文件以 SSH 或 PowerShell 用户身份完成。这很重要,因为这些用户通常无法提升权限。如果想将文件上传到需要特权的位置,我们建议将它们上传到临时位置,然后使用 shell provisioner 将它们移动到位。
选项
file provisioner 只有两个选项,都是必须的:
- source (string) - 要上传的文件或目录的本地路径。
- destination (string) - 虚拟机中用于接收上传文件的远端路径。文件或目录通过 SCP 之上的 SSH 上传,因此路径必须对用户可写。SSH 用户可以通过运行
vagrant ssh-config来决定,默认是“vagrant”。
警告
虽然 file provisioner 确实支持尾部斜杠或“全局”,但由于用于在主机和虚拟机之间复制文件和文件夹的底层工具的差异,这可能会导致一些令人困惑的结果。例如,如果源和目标的尾部斜线定义如下:
config.vm.provision "file", source: "~/pathfolder", destination: "/remote/newlocation/"
你这是在告诉 vagrant 上传 ~/pathfolder 到 /remote/newlocation 下面:
newlocation
├── pathfolder
│ └── file.sh
1 directory, 2 files
此行为也可以通过下面的定义你的 file provisioner 来实现:
config.vm.provision "file", source: "~/pathfolder", destination: "/remote/newlocation/pathfolder"
另一个例子是在主机上使用 globing 来抓取文件夹内的所有文件,但不是顶层文件夹本身:
config.vm.provision "file", source: "~/otherfolder/.", destination: "/remote/otherlocation"
file provisioner 被定义为将 ~/otherfolder 下的所有文件包含到新位置 /remote/otherlocation。这个想法可以通过简单地让目标文件夹与源文件夹不同来实现:
config.vm.provision "file", source: "/otherfolder", destination: "/remote/otherlocation"
Vagrant 手册之 Provisioning - file 配置程序的更多相关文章
- Vagrant 手册之 Provisioning - Shell 配置程序
原文地址 Provisioner 命令:"shell" 示例: node.vm.provision "shell" do |s| s.inline = < ...
- Vagrant 手册之 Provisioning - File
原文地址 Provisioner 名字:"file" Vagrant 的 file provisioner 允许将文件或目录从主机上传到客户机. File provisioning ...
- Vagrant 手册之 Provisioning - 基本用法
原文地址 虽然 Vagrant 提供了用于配置虚拟机的多个选项,但是有标准用法,好多知识点对这个 provisioner 是通用的. 配置 首先,Vagrantfile 中配置的每个 provisio ...
- Vagrant 手册之 Provisioning - 概述
原文地址 通过 Vagrant 中的 provisioner 配置程序,可以在使用 vagrant up 启动虚拟机时,在虚拟机上执行安装软件.更改配置等操作. box 通常是通用的,而每个项目总有自 ...
- Vagrant 手册之 Vagrantfile - 配置版本
原文地址 配置版本是 Vagrant 1.1+(引入了大量新功能和配置选项) 能够与 Vagrant 1.0.x Vagrantfiles 保持向后兼容的机制. 现在运行 vagrant init 时 ...
- Vagrant 手册之 Vagrantfile - 机器设置 config.vm
原文地址 配置的命名空间:config.vm config.vm 中的设置修改 Vagrant 管理的机器的配置. 1. 可用的设置项 config.vm.boot_timeout Vagrant 等 ...
- Vagrant 手册之网络 - 公共网络 public network
原文地址 Vagrantfile 配置文件中公共网络的标识符:public_network,例如: config.vm.network "public_network" Vagra ...
- 配置程序成为Linux服务
最近写了个程序需要随Linux启动时自动运行起来, 查了一些方法后, 通过配置程序成为系统的服务实现了这个需求, 在此记录一下. 测试程序 #! /bin/sh while [ true ] do e ...
- SpringCloud系列三:SpringSecurity 安全访问(配置安全验证、服务消费端处理、无状态 Session 配置、定义公共安全配置程序类)
1.概念:SpringSecurity 安全访问 2.具体内容 所有的 Rest 服务最终都是暴露在公网上的,也就是说如果你的 Rest 服务属于一些你自己公司的私人业务,这样的结果会直接 导致你信息 ...
随机推荐
- 【mysql】select子句顺序
sleect…from (1)where (2)group by (3)having (4)order by (5)limit
- Java继承:super关键字、构造器、final用法
一.继承 继承好处 1.提高代码的重用性 2.提高代码的扩展性和维护性 3.为多态打下了基础 继承类型 继承子类创建对象的过程 二.super关键字的使用 理解:super代表父类的引用,用于访问父类 ...
- python之下载每日必应壁纸
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'jiangwenwen' from bs4 import BeautifulS ...
- 奇葩问题:Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey
使用mybatis,遇到Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey ...
- Python subprocess ffmpeg
# -*- coding:utf-8 -*- import os, sys, getopt import numpy as np import subprocess as sp import cv2 ...
- django 项目创建使用
1. web框架的本质: socket服务端 与 浏览器的通信 2. socket服务端功能划分: a. 负责与浏览器收发消息(socket通信) --> wsgiref/uWsgi/gunic ...
- [php] phar
build.php打包www目录: <?php class A{ public $a = 1; } $p = new Phar('test.phar',0,'test.phar'); $p-&g ...
- 对Promise的研究3
Promise.race() Promise.race方法同样是将多个 Promise 实例,包装成一个新的 Promise 实例. const p = Promise.race([p1, p2, p ...
- Jenkins必备插件
1.汉化插件 https://plugins.jenkins.io/localization-zh-cn 2.邮件发送 https://plugins.jenkins.io/email-ext 3.G ...
- // 62.是否有利润奖--lrj private boolean isProfitsAward; // 63.利润奖--lrj_price private String profitsAward;
// 62.是否有利润奖--lrj private boolean isProfitsAward; // 63.利润奖--lrj_price private String profitsAward; ...