Best practices for supporting different environments

25 views
Skip to first unread message

Larry Martell

unread,
Jul 7, 2017, 5:49:18 PM7/7/17
to Vagrant
I have a directory that sometimes is used in a native environment on bare metal and other times used in a VM started with vagrant up. The only difference is a few config files. What is the accepted way of getting the VM version of the config files in place when a vagrant up is run?

I tried running a setup.sh script that uses here docs and sed, but it seems like the script does not run. I have this line in my Vagrantfile:

web.vm.provision :shell, :path => "setup.sh" 

Alvaro Miranda Aguilera

unread,
Jul 10, 2017, 2:13:09 PM7/10/17
to vagra...@googlegroups.com
hello

as long in the same level where your Vagrantfile is, vagrant will copy setup.sh, set the execute flag and run it.

inside the VM you can do

cd /vagrant
sudo ./setup.sh and should have the same effect.



--
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 vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/81ca6346-88d2-422a-8fbb-e34fbd165bc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Larry Martell

unread,
Jul 10, 2017, 3:10:51 PM7/10/17
to vagra...@googlegroups.com
Thanks for the reply. I want to run on 'vargrant up' I realized I
needed to add :run => 'always' to make that happen. Now it's running
but I am still having issues.

The script creates a file with a here doc but the file does not get
created. There is no error on that, but no file. If I run the script
by hand the file is created. I have checked and it's not a permission
issue.

The second issue I have is that I am trying to access a file in a
subdir, and I get "No such file or directory" even though the path to
the file does exist and is accessible.

Alvaro Miranda Aguilera

unread,
Jul 10, 2017, 6:27:08 PM7/10/17
to vagra...@googlegroups.com
hello

if you can share what you have done, ie github project I can help

scripts, and Vagrantfile will make all easier.

run: "always" make the script to run each time vagrant up even after the first time.

imagine you have an script that does this.

pwd
id
echo $EUID

it will run and show the user and current directory 

the way the script is created is copy the file to a random location, set the executable bit and run it

if you run 

vagrant ssh -c 'sudo /vagrant/<script.sh>' should be the same when vagrant run it.

if you require local path, then your script should do that for you


#!/usr/bin/env bash

pwd

pushd /vagrant
pwd
#here what you need
popd


is one way to do it



--
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 vagrant-up+unsubscribe@googlegroups.com.

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



--
Alvaro

Larry Martell

unread,
Jul 10, 2017, 8:13:46 PM7/10/17
to vagra...@googlegroups.com
Thanks. I got it working. The issue was I need to use the path
/vagrant on all files I was trying to access. Your message gave me the
hints I needed to figure this out.

On Mon, Jul 10, 2017 at 6:27 PM, Alvaro Miranda Aguilera
Reply all
Reply to author
Forward
0 new messages