Options for config.vm.synced_folder

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Options for config.vm.synced_folder

James Newton
Hello Vagrant experts!

Is it possible to use config.vm.synced_folder to update the folder on the host machine rather than overwriting it on the guest?

I have a package where nginx is already installed, and I am hoping to have a copy of the /etc/nginx/ folder on the host machine, so that I can edit the files in it without resorting to SSH.  I discover that if I use...

    config.vm.synced_folder 'nginx/', '/etc/nginx'

... then the /etc/nginx/ folder on the virtual machine is replaced by the (intially) empty nginx folder on the host. What would be the options to use to achieve this?

Or is there a completely different technique for copying these files from the VM to the host, so that on the next vagrant up, the synchronization can work as expected?

Thanks in advance,

James

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/3fbb36a9-73a1-49a3-998e-bcb73aac6fc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

Alvaro Miranda Aguilera
Hello

Shared folder goes from host to guest

what you can do is copy the folder out and then mount it on the guest

however will be a bit late (after servides start) and you will be need to reload the services after.

So you can just copy the files to the location and restart/reload the service in one single script. to keep things simple.

Alvaro

On Tue, Aug 29, 2017 at 6:33 PM, James Newton <[hidden email]> wrote:
Hello Vagrant experts!

Is it possible to use config.vm.synced_folder to update the folder on the host machine rather than overwriting it on the guest?

I have a package where nginx is already installed, and I am hoping to have a copy of the /etc/nginx/ folder on the host machine, so that I can edit the files in it without resorting to SSH.  I discover that if I use...

    config.vm.synced_folder 'nginx/', '/etc/nginx'

... then the /etc/nginx/ folder on the virtual machine is replaced by the (intially) empty nginx folder on the host. What would be the options to use to achieve this?

Or is there a completely different technique for copying these files from the VM to the host, so that on the next vagrant up, the synchronization can work as expected?

Thanks in advance,

James

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/3fbb36a9-73a1-49a3-998e-bcb73aac6fc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0eychsEORGAeC%2BRfPzDZ8w_%2B3ekt9opSfqKXv3cgqS%2BsCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

James Newton
On 29 August 2017 at 22:38, Alvaro Miranda Aguilera <[hidden email]> wrote:
Shared folder goes from host to guest

what you can do is copy the folder out and then mount it on the guest

however will be a bit late (after servides start) and you will be need to reload the services after.

So you can just copy the files to the location and restart/reload the service in one single script. to keep things simple.

Hello Alvaro,

Thank you for your feedback.

Would it be impertinent to ask what script I could use to copy the files from the guest to the host? I am guessing that this would need to be done only once, since from that moment on, any changes in the host will be carried back to the guest.

Thanks in advance for your insights,

James 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAGNcf%2BHLyHnvFb%3DNjYPLOp0QvMY%3Dbvv3d0_BZsd8f7vk8mjuBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

Alvaro Miranda Aguilera
Hello

So Vagrant provison by default runs only once, when the VM is created

so your script can look like:

$script = <<SCRIPT
cp -ap /vagrant/nginx/* /etc/nginx/
chkconfig nginx on
service nginx reload
SCRIPT Vagrant.configure("2") do |config| config.vm.provision "shell", inline: $script end

and you put your files in nginx/ directory




On Tue, Aug 29, 2017 at 11:11 PM, James Newton <[hidden email]> wrote:
On 29 August 2017 at 22:38, Alvaro Miranda Aguilera <[hidden email]> wrote:
Shared folder goes from host to guest

what you can do is copy the folder out and then mount it on the guest

however will be a bit late (after servides start) and you will be need to reload the services after.

So you can just copy the files to the location and restart/reload the service in one single script. to keep things simple.

Hello Alvaro,

Thank you for your feedback.

Would it be impertinent to ask what script I could use to copy the files from the guest to the host? I am guessing that this would need to be done only once, since from that moment on, any changes in the host will be carried back to the guest.

Thanks in advance for your insights,

James 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAGNcf%2BHLyHnvFb%3DNjYPLOp0QvMY%3Dbvv3d0_BZsd8f7vk8mjuBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0exp6Rdwp7WKaU6%3DBeLk9aaXNsJYJB_9kFYZh%2By5x5x0CQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

James Newton
Thank you so much for your help!

On 29 Aug 2017 23:28, "Alvaro Miranda Aguilera" <[hidden email]> wrote:
Hello

So Vagrant provison by default runs only once, when the VM is created

so your script can look like:

$script = <<SCRIPT
cp -ap /vagrant/nginx/* /etc/nginx/
chkconfig nginx on
service nginx reload
SCRIPT Vagrant.configure("2") do |config| config.vm.provision "shell", inline: $script end

and you put your files in nginx/ directory




On Tue, Aug 29, 2017 at 11:11 PM, James Newton <[hidden email]> wrote:
On 29 August 2017 at 22:38, Alvaro Miranda Aguilera <[hidden email]> wrote:
Shared folder goes from host to guest

what you can do is copy the folder out and then mount it on the guest

however will be a bit late (after servides start) and you will be need to reload the services after.

So you can just copy the files to the location and restart/reload the service in one single script. to keep things simple.

Hello Alvaro,

Thank you for your feedback.

Would it be impertinent to ask what script I could use to copy the files from the guest to the host? I am guessing that this would need to be done only once, since from that moment on, any changes in the host will be carried back to the guest.

Thanks in advance for your insights,

James 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAGNcf%2BHLyHnvFb%3DNjYPLOp0QvMY%3Dbvv3d0_BZsd8f7vk8mjuBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/XVFPIOXU8aI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0exp6Rdwp7WKaU6%3DBeLk9aaXNsJYJB_9kFYZh%2By5x5x0CQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAGNcf%2BHb4dT5sNPB14Vy08%2BB8M7ZSDMLaSoC15kbGzos9xnEjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

Alvaro Miranda Aguilera
Please share back what you got working, so other people can learn from it.

Sharing is caring :D

Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0eyhQXamZv8%3DSd%2BCM2pSneeO9dENxY%3DwdH1eaHd1sLAeKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

James Newton
On Wednesday, 30 August 2017 01:06:35 UTC+3, Alvaro Miranda Aguilera wrote:
Please share back what you got working, so other people can learn from it.

Sharing is caring :D

 Hi Alviro,

The code you posted provoked errors, but it did give me a starting point from which to work out a solution. 

# cp -ap /vagrant/nginx/* /etc/nginx/ ## should be:
cp -ap /vagrant/nginx/. /etc/nginx/
# chkconfig nginx on
## chkconfig is not shipped with Ubuntu since 12.04,
## if my research is accurate. Should be:
service nginx start

To help others who may not be using the custom package that I have, I've prepared a Vagrantfile that can be used after a simple `vagrant init` in an empty folder:

# -*- mode: ruby -*-
# vi: set ft=ruby :

$script
= <<SCRIPT
# Install nginx.
apt
-get -y update
apt
-get -y install nginx
service nginx start

# Copy the nginx and www folders to the /vagrant folder, so that they
# can be synced with the host. The www and nginx folders will be
# created automatically. They don't need to exist on the host yet.
cp
-ap /etc/nginx/. /vagrant/nginx/
cp
-ap /var/www/. /vagrant/www/

# Syncing must be done as a second step. Uncomment the lines beginning
# #*# below after the first `vagrant up`, then use `vagrant reload`
SCRIPT


Vagrant.configure("2") do |config|
  config
.vm.box = "ubuntu/xenial64"

 
#Run a provisioning script on first launch
  config
.vm.provision "shell", inline: $script

 
## Sync the www and nginx folders, so that they can be edited on
 
## the host machine.
 
## Uncomment the next line only after the box has been provisioned,
 
## otherwise the host's nginx/folder will overwrite the
 
## guest's installation.
 
#*#config.vm.synced_folder 'www', '/var/www'
 
#*#config.vm.synced_folder 'nginx', '/etc/nginx'

 
## On the first `vagrant up`, Vagrant will automatically create a
 
## /vagrant file at the root of the guest, and sync it with the
 
## folder that contains this Vagrantfile. This is necessary so that
 
## the command `cp -ap /etc/nginx/. /vagrant/nginx/` can copy the
 
## contents of the /etc/nginx/ folder to the host.
 
##
 
## On subsequent launches, only the ./www/ and ./nginx/ folders need
 
## to be synced, so you can uncomment the line below.
 
#*#config.vm.synced_folder '.', '/vagrant', disabled: true
end

This installed nginx and copied the contents of the /etc/nginx/ and /var/www/ directories to the host. I then manually uncommented three lines (as shown in bold below) and called vagrant reload.

# -*- mode: ruby -*-
# vi: set ft=ruby :

$script
= <<SCRIPT
# Install nginx.
apt
-get -y update
apt
-get -y install nginx
service nginx start

# Copy the nginx and www folders to the /vagrant folder, so that they
# can be synced with the host. The www and nginx folders will be
# created automatically. They don't need to exist on the host yet.
cp
-ap /etc/nginx/. /vagrant/nginx/
cp
-ap /var/www/. /vagrant/www/

# Syncing must be done as a second step. Uncomment the lines beginning
# #*# below after the first `vagrant up`, then use `vagrant reload`
SCRIPT


Vagrant.configure("2") do |config|
  config
.vm.box = "ubuntu/xenial64"

 
#Run a provisioning script on first launch
  config
.vm.provision "shell", inline: $script

 
## Sync the www and nginx folders, so that they can be edited on
 
## the host machine.
 
## Uncomment the next line only after the box has been provisioned,
 
## otherwise the host's nginx/folder will overwrite the
 
## guest's installation.
 
config.vm.synced_folder 'www', '/var/www'
  config
.vm.synced_folder 'nginx', '/etc/nginx'


 
## On the first `vagrant up`, Vagrant will automatically create a
 
## /vagrant file at the root of the guest, and sync it with the
 
## folder that contains this Vagrantfile. This is necessary so that
 
## the command `cp -ap /etc/nginx/. /vagrant/nginx/` can copy the
 
## contents of the /etc/nginx/ folder to the host.
 
##
 
## On subsequent launches, only the ./www/ and ./nginx/ folders need
 
## to be synced, so you can uncomment the line below.
  config.vm.synced_folder '.', '/vagrant', disabled: true
end

It seems cumbersome to have to make these manual changes and to run vagrant reload. Is it possible to modify this script so that the config.vm.synced_folder calls are made only if /etc/nginx/ already exists, and vagrant reload is called automatically if not?

Having a single, unchanging file that gets read twice would make sharing the Vagrant package much more straightforward.

Thanks in advance for your ideas,

James


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/565994ce-4612-4cfc-ae01-48a12983e5b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Options for config.vm.synced_folder

Alvaro Miranda Aguilera
Once all is in place you can test with

vagrant destroy
vagrant up


Copying files from guest to host into the /vagrant folder is good to put all into the project, you can have all in Source control.

Once is done, the user experience for the new box will be

git clone <url>
cd <dir>
vagrant up

Alvaro

On Sat, Sep 2, 2017 at 5:04 PM, James Newton <[hidden email]> wrote:
On Wednesday, 30 August 2017 01:06:35 UTC+3, Alvaro Miranda Aguilera wrote:
Please share back what you got working, so other people can learn from it.

Sharing is caring :D

 Hi Alviro,

The code you posted provoked errors, but it did give me a starting point from which to work out a solution. 

# cp -ap /vagrant/nginx/* /etc/nginx/ ## should be:
cp -ap /vagrant/nginx/. /etc/nginx/
# chkconfig nginx on
## chkconfig is not shipped with Ubuntu since 12.04,
## if my research is accurate. Should be:
service nginx start

To help others who may not be using the custom package that I have, I've prepared a Vagrantfile that can be used after a simple `vagrant init` in an empty folder:

# -*- mode: ruby -*-
# vi: set ft=ruby :

$script
= <<SCRIPT
# Install nginx.
apt
-get -y update
apt
-get -y install nginx
service nginx start

# Copy the nginx and www folders to the /vagrant folder, so that they
# can be synced with the host. The www and nginx folders will be
# created automatically. They don't need to exist on the host yet.
cp
-ap /etc/nginx/. /vagrant/nginx/
cp
-ap /var/www/. /vagrant/www/

# Syncing must be done as a second step. Uncomment the lines beginning
# #*# below after the first `vagrant up`, then use `vagrant reload`
SCRIPT


Vagrant.configure("2") do |config|

  config
.vm.box = "ubuntu/xenial64"

 
#Run a provisioning script on first launch
  config
.vm.provision "shell", inline: $script

 
## Sync the www and nginx folders, so that they can be edited on
 
## the host machine.
 
## Uncomment the next line only after the box has been provisioned,
 
## otherwise the host's nginx/folder will overwrite the
 
## guest's installation.
 
#*#config.vm.synced_folder 'www', '/var/www'
 
#*#config.vm.synced_folder 'nginx', '/etc/nginx'

 
## On the first `vagrant up`, Vagrant will automatically create a
 
## /vagrant file at the root of the guest, and sync it with the
 
## folder that contains this Vagrantfile. This is necessary so that
 
## the command `cp -ap /etc/nginx/. /vagrant/nginx/` can copy the
 
## contents of the /etc/nginx/ folder to the host.
 
##
 
## On subsequent launches, only the ./www/ and ./nginx/ folders need
 
## to be synced, so you can uncomment the line below.
 
#*#config.vm.synced_folder '.', '/vagrant', disabled: true
end

This installed nginx and copied the contents of the /etc/nginx/ and /var/www/ directories to the host. I then manually uncommented three lines (as shown in bold below) and called vagrant reload.

# -*- mode: ruby -*-
# vi: set ft=ruby :

$script
= <<SCRIPT
# Install nginx.
apt
-get -y update
apt
-get -y install nginx
service nginx start

# Copy the nginx and www folders to the /vagrant folder, so that they
# can be synced with the host. The www and nginx folders will be
# created automatically. They don't need to exist on the host yet.
cp
-ap /etc/nginx/. /vagrant/nginx/
cp
-ap /var/www/. /vagrant/www/

# Syncing must be done as a second step. Uncomment the lines beginning
# #*# below after the first `vagrant up`, then use `vagrant reload`
SCRIPT


Vagrant.configure("2") do |config|

  config
.vm.box = "ubuntu/xenial64"

 
#Run a provisioning script on first launch
  config
.vm.provision "shell", inline: $script

 
## Sync the www and nginx folders, so that they can be edited on
 
## the host machine.
 
## Uncomment the next line only after the box has been provisioned,
 
## otherwise the host's nginx/folder will overwrite the
 
## guest's installation.
 
config.vm.synced_folder 'www', '/var/www'
  config
.vm.synced_folder 'nginx', '/etc/nginx'


 
## On the first `vagrant up`, Vagrant will automatically create a
 
## /vagrant file at the root of the guest, and sync it with the
 
## folder that contains this Vagrantfile. This is necessary so that
 
## the command `cp -ap /etc/nginx/. /vagrant/nginx/` can copy the
 
## contents of the /etc/nginx/ folder to the host.
 
##
 
## On subsequent launches, only the ./www/ and ./nginx/ folders need
 
## to be synced, so you can uncomment the line below.
  config.vm.synced_folder '.', '/vagrant', disabled: true
end

It seems cumbersome to have to make these manual changes and to run vagrant reload. Is it possible to modify this script so that the config.vm.synced_folder calls are made only if /etc/nginx/ already exists, and vagrant reload is called automatically if not?

Having a single, unchanging file that gets read twice would make sharing the Vagrant package much more straightforward.

Thanks in advance for your ideas,

James


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/565994ce-4612-4cfc-ae01-48a12983e5b2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ewPW-vXbndqFoLRyQ5mavihogmX1nR5MiSLYNnWgaZ2fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.