Access django server in vagrant virtualbox on host machine? - vagrant

I am using windows and putty to ssh to vagrant virtualbox.I cannot access the django server running in vagrant virtualbox using http://localhost:9991
I have disabled my firewall as well
here's my vagrant file:
VAGRANTFILE_API_VERSION = "2"
def command?(name)
`which #{name}`
$?.success?
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# For LXC. VirtualBox hosts use a different box, described below.
config.vm.box = "fgrehm/trusty64-lxc"
# The Zulip development environment runs on 9991 on the guest.
config.vm.network "forwarded_port", guest: 9991, host: 9991, host_ip: "127.0.0.1"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder ".", "/srv/zulip"
# Specify LXC provider before VirtualBox provider so it's preferred.
config.vm.provider "lxc" do |lxc|
if command? "lxc-ls"
LXC_VERSION = `lxc-ls --version`.strip unless defined? LXC_VERSION
if LXC_VERSION >= "1.1.0"
# Allow start without AppArmor, otherwise Box will not Start on Ubuntu 14.10
# see https://github.com/fgrehm/vagrant-lxc/issues/333
lxc.customize 'aa_allow_incomplete', 1
end
end
end
config.vm.provider "virtualbox" do |vb, override|
override.vm.box = "ubuntu/trusty64"
# 2GiB seemed reasonable here. The VM OOMs with only 1024MiB.
vb.memory = 2048
end
$provision_script = <<SCRIPT
set -x
set -e
sudo apt-get update
sudo apt-get install -y python-pbs
/usr/bin/python /srv/zulip/provision.py
SCRIPT
config.vm.provision "shell",
# We want provision.py to be run with the permissions of the vagrant user.
privileged: false,
inline: $provision_script
end
How do i access the server from host(Windows)?

I would suggest (on the Guest):
sudo netstat -lnutp
and having a look at what ports are open, and the process which owns them. If the one you want is missing, make sure the service which is responsible for it has been started, or start it yourself. From the looks of your Vagrantfile, this would be the "Zulip development environment".

Related

Vagrantbox with Hyper-V not starting

I'm trying to setup a vagrantbox with Hyper-V on my local windows-10 mashine. My Workstation is running behind a proxy, but I configured a local cntlm proxy to get around these limitations. Proxy settings work fine since I was able to install a vagrant plugin and downloan a box image.
But now my guest linux does not start up and I am running out of ideas.
My vagrant file
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-18.04" # ubuntu 18.04 image with support for virtual box and Hyper-V
config.vm.hostname = "skywalker"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.provider "hyperv" do |hv|
hv.memory = "2048"
end
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" # prevent tty errors
# install the vagrant plugin "vagrant-cachier" to cache downloaded artifacts
if Vagrant.has_plugin?("vagrant-cachier")
config.cache.scope = :box
end
# vagrant behing local cntlm proxy if plugin exists (= provinzial win10 workstation)
if !Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = "http://localhost:3128/"
config.proxy.https = "http://localhost:3128/"
config.proxy.no_proxy = "localhost, 127.0.0.1"
end
# --------------------------------------------------------------------------
# provision virtual mashine (basic setup) and install applications in VM
#config.vm.provision "shell", path: "scripts/install-ansible.sh"
config.vm.provision "shell", path: "scripts/install-ncdu.sh"
config.vm.provision "shell", path: "scripts/install-git.sh"
config.vm.provision "shell", path: "scripts/install-openjdk-11.sh"
config.vm.provision "shell", path: "scripts/install-maven.sh"
config.vm.provision "shell", path: "scripts/install-node-npm.sh"
config.vm.provision "shell", path: "scripts/install-docker.sh"
config.vm.provision "shell", path: "scripts/install-docker-compose.sh"
# npm webserver
config.vm.provision "shell", path: "apps/install-npm-apps.sh"
config.vm.network "forwarded_port", guest: 8000, host: 8000
# artifactory setup (start artifactory after vm startup)
config.vm.network "forwarded_port", guest: 8081, host: 8081 # artifactory from docker
config.vm.network "forwarded_port", guest: 8082, host: 8082 # artifactory from docker
# See README.md for Artifactory in Docker
end
Starting the box with this settings results in
C:\home\work\workspace\vagrant-boxes\skywalker (master -> origin)
λ vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
default: Successfully imported VM
default: Configuring the VM...
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP: fe80::215:5dff:fe02:8b01
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: fe80::215:5dff:fe02:8b01:22
default: SSH username: vagrant
default: SSH auth method: private key
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.
On a different mashine with VirtualBox as VM provider this Vagrantfile works fine. Sadly I cannot use any VM provider other than Hyper-V on my windows mashine due to limitations which are out of my control ...
I set up Hyper-V using Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All.
Any ideas? Thanks in advance and best regards. Sebastian
I went through this exercise last week and saw similar problems. I made lot of progress following these steps and the vm's get spun up at a reasonable time under windows 10 hyper-v. This is what i did.
Followed this blog and tried creating a vm successfully first.
https://win32.io/posts/Vagrant-Install-HyperV
Then i created a simple vagrantfile and got it to work successfully. Here is mine ,
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.hostname = 'utility-server-1'
config.vm.network 'public_network', bridge: 'Internet'
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "hyperv" do |vb|
vb.memory = "4024"
vb.cpus = 2
vb.vmname = 'utility-server-1'
end
end
Once this works, add more complex steps from your vagrantfile, like shell scripts and forwarded ports.

The following SSH command responded with a non-zero exit status after upgrade to Ubuntu 18.04

I have a small problem with setting up my working environment after upgrade to Ubuntu 18.04. Vagrant version is 2.0.0.
Vagrant File
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "debian/jessie64"
# config.vm.box = "ubuntu/xenial64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
config.vm.network "forwarded_port", guest: 80, host: 8888
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder ".", "/vagrant-nfs", type: :nfs, mount_options: ['rw', 'vers=3', 'tcp', 'fsc' ,'actimeo=2']
config.bindfs.bind_folder "/vagrant-nfs", "/srv/bspotted.net/app", :owner => "vagrant", :group => "vagrant"
config.vm.network :private_network, ip: "192.168.33.15"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--name", "bspotted", "--memory", "2048"]
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
# Ansible provisioner.
config.vm.provision "ansible_local" do |ansible|
ansible.version = "2.3.2.0"
ansible.install_mode = "pip"
ansible.provisioning_path = "/srv/bspotted.net/app"
ansible.playbook = "orchestration/vagrant.yml"
ansible.verbose = "vvv"
end
end
For the record I have an older version Ubuntu 16.10 on my other laptop and everything is working properly, this is the output of the vagrant up --debug &> vagrant.log command here.
Everything fall apart when setup reach
==> default: Preparing to edit /etc/exports. Administrator privileges will be required...
==> default: Mounting NFS shared folders...
after aprox 5 minutes, it will show
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o vers=3,udp,rw,vers=3,tcp,fsc,actimeo=2 192.168.33.1:/home/copser/Documents/Bspotted /vagrant-nfs
Stdout from the command:
Stderr from the command:
mount.nfs: Connection timed out
Problem is solved after I've changed the version of nfs,
`config.vm.synced_folder ".", "/vagrant-nfs", type: :nfs, mount_options: ['rw', 'vers=3', 'tcp', 'fsc' ,'actimeo=2']`
to
config.vm.synced_folder ".", "/vagrant-nfs", type: :nfs, mount_options: ['rw', 'vers=4', 'tcp', 'fsc' ,'actimeo=2']
just to make it clear I've changed vers=3 to vers=4, and no everything is working fine. You can check my correspondence with vagrant contributors here.

Vagrant Vagrantfile config

I have this vagranfile for box "centos/7"
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/home/vagrant"
config.vm.provision "shell", path: "./conf/bitrix-env.sh"
config.vm.boot_timeout = 100
config.vm.provider :virtualbox do |vb|
vb.gui = true
vb.memory = "1024"
end
end
vagrant up - command works clear, but scripts in provision don't install
after i tried to start vagrant provision, but had an error:
SSH is getting permission denied errors when attempting to connect
to the IP for SSH. This is usually caused by network rules and not being
able to connect to the specified IP. Please try changing the IP on
which the guest machine binds to for SSH.
How can i fix this and install all provisions?
The problem is due to the below line in your vagrantfile
config.vm.synced_folder '.', '/home/vagrant'
The authorized_keys file for the vagrant user is located in /home/vagrant/.ssh inside the vagrant machine, which enables to ssh into the vagrant box.
As you are mounting your current directory to /home/vagrant, all the contents of /home/vagrant are over-written and there is no authorized key file.
Change the mount path to anything except /home/vagrant, and you will able to ssh into the machine. As example
config.vm.synced_folder '.', '/home/vagrant/somepath'

I am trying to setup the vagrant environment but this error occurs default: VM not created. Moving on

I am working on to setup the vagrant environment on the mac. I have done the following steps.
Installed the virtualbox
Clone my project to local disk
Downloaded the box and added the box successfully
I have also edit the vagrant file and add the name of box to the vagrant file.
Now when i run the command "vagrant provision" this error occurs
default: VM not created. Moving on...
I have google it a lot but no idea that what to do.
sudo vagrant box list
Result:
bpc_box (virtualbox, 0)
new_box (virtualbox, 0)
Vagrant file
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bpc_box"
config.vm.synced_folder "workspace/", "/vagrant"
config.vm.network "forwarded_port", guest: 8080, host: 8085
config.vm.network "forwarded_port", guest: 80, host: 8090
config.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.memory = 2048
end
config.vm.provider "parallels" do |prl|
prl.cpus = 2
prl.memory = 2048
end
config.ssh.forward_agent = true
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provisioning/main.yml"
end
end
You need to spin the VM first, the first command to run is
$ vagrant up
this will bring your VM up and provision it if this is the first time this particular VM has been started.
once the VM is up and running you can run vagrant provision to force the (re)provisioning of the running VM.
You can read more about vagrant cli option at https://www.vagrantup.com/docs/cli/

Vagrant up - The Following settings shouldn't exist: vm (rethinkdb-vagrant)

Trying to setup rethinkdb using https://github.com/RyanAmos/rethinkdb-vagrant
C:\rethinkdb-vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
VirtualBox Provider:
* The following settings shouldn't exist: vm
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Ubuntu 12.04, 64 bit
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
# Providers
config.vm.provider :virtualbox do |p|
p.vm.customize ['modifyvm', :id, '--memory', '512', '--ioapic', 'on']
end
# SSH
config.ssh.username = "vagrant"
# Port Forwarding
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.network :forwarded_port, guest: 28015, host: 28015
config.vm.network :forwarded_port, guest: 29015, host: 29015
# Attempt to 'guess' the default network
config.vm.network :public_network, :bridge => 'en0: Wi-Fi (AirPort)'
# Provisioning
config.vm.provision :shell do |sh|
sh.inline = <<-EOF
export DEBIAN_FRONTEND=noninteractive;
apt-get update --assume-yes;
apt-get install --assume-yes python-software-properties;
add-apt-repository --yes ppa:rethinkdb/ppa 2>&1;
apt-get update --assume-yes;
apt-get install --assume-yes rethinkdb;
sed -e 's/somebody/root/g' -e 's/somegroup/root/g' -e 's/# bind=127.0.0.1/bind=all/g' /etc/rethinkdb/default.conf.sample > /etc/rethinkdb/instances.d/default.conf
rethinkdb create -d /var/lib/rethinkdb/instances.d/default 2>&1;
service rethinkdb start;
EOF
end
end
The issue is at this section:
# Providers
config.vm.provider :virtualbox do |p|
p.vm.customize ['modifyvm', :id, '--memory', '512', '--ioapic', 'on']
end
where p.vm.customize should just be p.customize since as the outer loop shows, vm is parent to provider and customize hangs directly off of provider.
So the correct block would be:
# Providers
config.vm.provider :virtualbox do |p|
p.customize ['modifyvm', :id, '--memory', '512', '--ioapic', 'on']
end
If you run:
vagrant global-status
you will see all the possible machines that might be running on your computer.
Then take those machines and go
vagrant suspend [machine id]
Further more you can open Virtual Box and Power Off those machines manually from that GUI, which should free up the ports.

Resources