opticyclic
opticyclic

Reputation: 8106

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 (e.g. jars that are not in public repos) in the files section and copy them from there to guest using puppet.

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?

Upvotes: 1

Views: 1099

Answers (1)

rojs
rojs

Reputation: 648

Use the creates parameter on an exec resource calling wget.

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. Add some versioning of the files and pass what version you want to the command, easy to drop in newer versions.

Upvotes: 4

Related Questions