How to put files into Vagrant? - vagrant

I did an internship and they used vagrant so all the developers whould run the same latest version of the web application.
But now i want to create my own vagrant webserver.
I got to the point that i setup vagrant using the hashicorp/precise32 box.
I got nginx running on my own special ip adress that i changed in the hosts file.
So now i can go to mytestsite.com and it will show me welcome to nginx.
But now my question is, how can i get my own file(small test web application) into the vagrant server because i do not know how to transfer my files to vagrant.
And how can i let my friends use my vagrant test web application.
Thank you for your help!
Sincerely Mex
19 years old
web application student in the Netherlands

By default vagrant will have a synced folder between your vm and the host machine. It is in the same folder as the vagrantfile and can accessed through /vagrant on your host machine.
However if you want more customization and mount certain folders on your host machine and sync them to the vagrant VM it can be done in the vagrant file as follows:
Vagrant.configure("2") do |config|
# other config here
config.vm.synced_folder "src/", "/srv/website"
end
Here is a quick guide to get you started using vagrants synced folders and the example i posted

Related

Vagrant cannot vagrant up the box packaged from ubuntu xenial64 16.04

I have a custom vagrant box based on the offcial box ubuntu 16.04.
I simplly run like this to get the packaged box.
vagrant init ubuntu/xenial64; vagrant up --provider virtualbox
vagrant up
vagrant ssh # enter the virtual machine and do some custom change on it
vagrant halt
vagrant package --vagrantfile Vagrantfile --output custom_ubuntu1604.box
and then i copy the file custom_ubuntu1604.box to another directory, i use the box like this:
vagrant box add ubuntu1604base custom_ubuntu1604.box
vagrant init ubuntu1604base
vagrant up # at this point the machine will be stopped at "Started Journal Servie"
my new virtualbox machine base on the new packaged box will stop at:
the screenshot
And finally it timed out:
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within the
configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that Vagrant
had when attempting to connect to the machine. These errors are
usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes. Verify
that authentication configurations are also setup properly, as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
Try to set config.vm.boot_timeout in Vagrantfile more than default e.x.600. From my experience I found out it take a long time at the first time to connecting guest machine.
For example
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox"
config.vm.boot_timeout = 600
end

Is it possible to provision vagrant boxes from puppet modules located outside of the vagrant folder?

I have a production server architecture that is quite complex that involves several types and tiers of servers including: Web, Varnish, HAProxy, ELK, Database, Sensu, etc. The production architecture is provisioned with puppet masters and the puppet code for the masters is provisioned with Git through many, submodules.
I want to connect these Git repos to VM's locally to further develop pieces of the puppet architecture. However each Vagrant VM requires a complete self contained copy of all of the Git repos in order to stand up just one VM. This seems like a very inefficient use of drive space for local development on what will be potentially a dozen different types of servers.
Is there a way to point all of the Vagrant VM's VagrantFiles to a common local folder outside of the vagrant directory such that each Vagrant instance can still read the folder and provision the server?
Edited --
Based on comment from #Treminio, here is the portion of my VagrantFile showing the attempt to declare an absolute path from host computers root:
config.vm.provision "puppet" do |puppet|
puppet.manifest_file = "init.pp"
puppet.manifests_path = "/Users/jdugger/vm/puppet/manifests"
puppet.module_path = "/Users/jdugger/vm/puppet/modules"
puppet.hiera_config_path = "/Users/jdugger/vm/puppet/hieradata"
end
... and the error response by Vagrant:
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/jdugger/vm/pupt/vagrant
default: /vagrant_data/scripts => /Users/jdugger/scripts
default: /tmp/vagrant-puppet/modules-169f1d27ef31a534405e2e9fcde2eedf => /Users/jdugger/vm/puppet/modules
default: /tmp/vagrant-puppet/manifests-be5a69bfb646cf9329b8921f221ffab8 => /Users/jdugger/vm/puppet/manifests
==> default: Running provisioner: puppet...
The `puppet` binary appears not to be in the PATH of the guest. This
could be because the PATH is not properly setup or perhaps Puppet is not
installed on this guest. Puppet provisioning can not continue without
Puppet properly installed.
This response may not be because of the puppet path - not sure - It appears that puppet is not on the guest box (isn't it supposed to be running from Vagrant?). No version comes up when with:
[vagrant#localhost ~]$ puppet --version
Response is:
-bash: puppet: command not found
Update ---
#Treminio is correct. I have been able to provision with puppet manifests and modules external to the vagrant/ directory. The Path problem appears to be because Puppet is not installed on the guest VM. To resolve this I added a shell script found here:
http://garylarizza.com/blog/2013/02/01/repeatable-puppet-development-with-vagrant/
This was added just before the puppet provisioning declaration. Just as a note there doesn't seem to be a lot of advanced examples that demonstrate the external file capability or that you need to install puppet outside of the puppet provisioner.
However each Vagrant VM requires a complete self contained copy of all of the Git repos in order to stand up just one VM.
This is incorrect.
What you want to change is the puppet.module_path value.
It can be any location on your host's disk, and Vagrant will automatically mount it inside your VM.

How create an ssh connection from vagrant to a specific virtual machine? Can I create a connection to a VM installed on WMware?

I am absolutly new in Vagrant and in Apache Storm.
I am following an online course where show the following situation.
1) There is an Ubuntu virtual machine installed on Virtual Box
2) On the physic machine (the same where is installed Virtual Box and that run the Ubuntu VM) it is installed Vagrant
Ok, from the physic machine, it log into the virtual machine using this statment:
vagrant ssh
and show that it is created a connection to the installed Ubuntu VM.
Here the first doubt: how it know what is the exact virtualized system? What happen if I have installed more than one VM on Virtual Box (with the previous command it is not specified to what installed VM have to be connected)
Another doubt is: I don't use Virtual Box but I use WMware workstation? How can I use the vagrand ssh command to create a connection to a specific VM installed on my WMware workstation?
I'd try to answer a few points from your question -
First, in vagrant language the physic machine will be the host and the VM is called the guest (or guest VM)
Vagrant knows how to connect to the VM it did create as it maintains the Id of the created VM into a .vagrant directory where you have initialized the Vagrantfile.
You can run vagrant global-status and you will have an output with all the VMs that vagrant managed along with the Id, Name and Provider information.
The provider can be VirtualBox or VMWare or anything else. The same in the .vagrant directory you will have subdirectory for the provider (e.g. a directory .vagrant/machines/default/virtualbox or .vagrant/machines/default/vmware_xxx) by default vagrant will start the Virtualbox provider but you can specify the --provider=XXX option when setting up the VM for the 1st time and then vagrant will create the VM for this specific provider and further command on this VM (ssh, reload ...) will work on this specific provider.

Accessing files within vagrant using pycharm on host

I am reading online docs of jetbrains but unable to understand that how does one access files on the vagrant VM from pycharm running on a host. Do I need to do tool>deployment>configure and than setup a SFTP to 127.0.0.1? If yes, I tried that but its unable to connect (even using default vagrant user which is password-less).
This is a common use-case and I am sure many would have done it. What am I missing?
I got this working by doing the following:
Tools -> Deployment -> Configuration
Add server (SFTP)
host: 127.0.0.1
Port: 2222
Root Path: /home/vagrant
user name: vagrant
password: vagrant
At this point you can test your connection. It should work. If it doesn't maybe your vagrant is not working properly?

Point Vagrant to a Local API

Hey guys I have two vagrant machines running, one is the app code base and the other is the api code base for the app. I want to be able to do a curl call from my app machine to the api machine.
On my computer I can call both because I have them in my etc/hosts file, but what do I need to do to successfully request from vagrant to vagrant.
I tried to go into my app vagrant machine's etc/hosts and add the domain with the 127.0.0.1 but no cigar.
So it turns out that Vagrant makes your guest machine's ip to 10.0.2.2. So what I did on my App code base vagrant machine. I edited the /etc/hosts to;
10.0.2.2 api.local.com
previously I tried 127.0.0.1, and that didn't work, so I just checked the apache access logs saw the ip and gave that a whirl. and that worked.
On my local machine I have;
127.0.0.1 api.local.com
I hope this helps.

Resources