简体   繁体   English

使用流浪汉/人偶下载文件(如果不存在)

[英]Use Vagrant/Puppet To Download File If Not Exist

When developing my vagrant/puppet scripts I do a lot of vagrant destroy and vagrant up to make sure that the provisioning works from a clean slate. 开发我的无业游民/木偶脚本时,我会进行大量的无业游民销毁和无业游民,以确保资源调配工作是干净的。

For this reason and for the sake of bandwidth and time, I put large files that I need to install (eg jars that are not in public repos) in the files section and copy them from there to guest using puppet. 因此,出于带宽和时间的考虑,我将需要安装的大文件(例如不在公共仓库中的jar)放在文件部分,然后使用and将它们从那里复制到guest虚拟机。

This is great for me whilst developing but it is a bit of a barrier to entry for others as I have a readme with a large number of dependencies that need downloading to certain directories on the host before the provisioning can start. 这对我在开发时非常有用,但对其他人来说却是一个进入障碍,因为我有一个具有大量依赖项的自述文件,需要在开始供应之前将其下载到主机上的某些目录。

Once I am certain that my scripts are ready I could change them to point to an internal server that hosts the files, however, I don't like this last minute changing of the scripts. 一旦确定脚本准备就绪,就可以将其更改为指向承载文件的内部服务器,但是,我不喜欢最后一刻更改脚本。

Is it possible to have vagrant/puppet check if the files exist locally on the host and if not download them from a specified URL? 是否可以让vagrant / puppet检查文件是否在主机上本地存在,以及是否不从指定的URL下载?

Use the creates parameter on an exec resource calling wget. 在调用wget的exec资源上使用created参数。

exec {'download-tar-file':
  command => 'wget -O /tmp/tar.file http://somewhere.com/tar.file',
  creates => '/tmp/tar.file',
}

With this, exec only fires if the file isn't there. 有了这个,exec仅在文件不存在时才触发。 Add some versioning of the files and pass what version you want to the command, easy to drop in newer versions. 添加文件的某些版本控制,然后将所需的版本传递给命令,轻松添加新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM