Copy/Upload files from host to the guest

2,354 views
Skip to first unread message

John Riker

unread,
Jun 10, 2013, 1:54:45 AM6/10/13
to vagra...@googlegroups.com
I believe this ruby script would allow me to copy a file from host to the guest system (scripted version, not manual copy). I want to add this as part of a custom recipe, but not sure what would be the wrapper/proviosioner that I should be using to get this working. Obviously the one below is not correct, since it is copied from provisioner section of vagrantfile.
 
config.vm.provision :chef_solo do |chef|
   chef.src_file = "/users/xyz/abcd.xml"
   chef.target_file = "/tmp/abcd.xml"
   chef.src_file = Chef::Config[:target_file]
end

Is there another resource/command line I should be using? In the google groups I found a upload command on vm.channel, but was again not sure of the wrapper around it or if it is part of a recipe.

    env = Vagrant::Environment.new
    env.primary_vm.channel.upload(file,dir)


Any help is greatly appreciated.

Thanks

Adam Fields

unread,
Jun 10, 2013, 10:02:30 AM6/10/13
to vagra...@googlegroups.com

On Jun 10, 2013, at 1:54 AM, John Riker <three...@gmail.com> wrote:

> I believe this ruby script would allow me to copy a file from host to the guest system (scripted version, not manual copy). I want to add this as part of a custom recipe, but not sure what would be the wrapper/proviosioner that I should be using to get this working. Obviously the one below is not correct, since it is copied from provisioner section of vagrantfile.

It kind of depends on what files you're copying and whether it's something you can distribute or needs to be specific to each host.

For almost everything, I package them up in a subfolder in the vagrant config directory and then do something like this:

config.vm.provision :shell, :inline => "cp /vagrant/vm_files/vm_hosts /etc/hosts"

John Riker

unread,
Jun 10, 2013, 11:26:50 AM6/10/13
to vagra...@googlegroups.com
Thanks...Something I want to distribute...I presume we add this to the vagrantfile provisioners. For some reason, vagrant reload is unable to find the source file, though I gave the absolute path as

config.vm.provision :shell, :inline => "cp /users/xyz/abcd.xml /tmp/abcd.xml"  I get the error as

[default] Running provisioner: Vagrant::Provisioners::Shell...
cp:
cannot stat `/users/xyz/abcd.xml'
: No such file or directory

Adam Fields

unread,
Jun 10, 2013, 11:58:27 AM6/10/13
to vagra...@googlegroups.com

On Jun 10, 2013, at 11:26 AM, John Riker <three...@gmail.com> wrote:

> Thanks...Something I want to distribute...I presume we add this to the vagrantfile provisioners. For some reason, vagrant reload is unable to find the source file, though I gave the absolute path as
>
> config.vm.provision :shell, :inline => "cp /users/xyz/abcd.xml /tmp/abcd.xml" I get the error as
>

It needs to be in a directory that's accessible to the vm. By default, the /vagrant directory inside the vm is mapped to the directory where your Vagrantfile is (which makes the most sense for files that are distributed with the vagrant config), but if you really must, you can add other synced folders and use one of those. So if you create a folder vm_files in the same directory as your Vagrantfile, it will be accessible from the vm at /vagrant/vm_files.

> [default] Running provisioner: Vagrant::Provisioners::Shell...
> cp:
> cannot stat `/users/xyz/abcd.xml'
> : No such file or directory
>
>
> On Monday, June 10, 2013 10:02:30 AM UTC-4, Adam Fields wrote:
>
> On Jun 10, 2013, at 1:54 AM, John Riker <three...@gmail.com> wrote:
>
> > I believe this ruby script would allow me to copy a file from host to the guest system (scripted version, not manual copy). I want to add this as part of a custom recipe, but not sure what would be the wrapper/proviosioner that I should be using to get this working. Obviously the one below is not correct, since it is copied from provisioner section of vagrantfile.
>
> It kind of depends on what files you're copying and whether it's something you can distribute or needs to be specific to each host.
>
> For almost everything, I package them up in a subfolder in the vagrant config directory and then do something like this:
>
> config.vm.provision :shell, :inline => "cp /vagrant/vm_files/vm_hosts /etc/hosts"
>
>
> --
> You received this message because you are subscribed to the Google Groups "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

John Riker

unread,
Jun 10, 2013, 12:12:03 PM6/10/13
to vagra...@googlegroups.com
The path /vagrant/vm_files worked....thanks much.

Adam Fields

unread,
Jun 10, 2013, 12:16:23 PM6/10/13
to vagra...@googlegroups.com

On Jun 10, 2013, at 12:12 PM, John Riker <three...@gmail.com> wrote:

> The path /vagrant/vm_files worked....thanks much.
>

I've posted this before, but I have a bunch of other helpful tips in this blog post, along with a sample Vagrantfile:

http://workstuff.tumblr.com/post/50911984233/some-tips-on-getting-started-with-vagrant-and-chef
Reply all
Reply to author
Forward
0 new messages