Monday, May 2, 2016

Using Vagrant to create mulitple hosts and accessing the machines using Vagrant networking

$ gem install json


Ruby interpreter for debugging
http://stackoverflow.com/questions/2814077/how-do-i-find-the-ruby-interpreter

Ruby hash
http://ruby-doc.org/core-2.0.0/Hash.html

A Stackoverflow post on Ruby variable syntax
http://stackoverflow.com/questions/28339025/ruby-on-rails-colon-at-back-or-front-of-variables

Vagrant multi-machine examples:
VAGRANT + YAML
http://blog.scottlowe.org/2016/01/18/multi-machine-vagrant-json/
https://thornelabs.net/2014/11/13/multi-machine-vagrantfile-with-shorter-cleaner-syntax-using-json-and-loops.html

Summary of methods...
https://sukhjinderkainth.wordpress.com/2015/08/19/create-a-multi-machine-vagrant-config-file/

JSON include into Vagrantfile example:
http://blog.scottlowe.org/2016/01/18/multi-machine-vagrant-json/

HDP Cluster on your laptop
https://uprush.github.io/hdp/2014/12/29/hdp-cluster-on-your-laptop/

Find Vagrant boxes at Hasicorp
https://atlas.hashicorp.com/boxes/search

SSH to Vagrant boxes
http://scala-lang.org/

Adding users and their passwords to Vagrant through the Vagrantfile
http://stackoverflow.com/questions/25758737/vagrant-login-as-root-by-default
http://stackoverflow.com/questions/32454576/vagrant-ssh-using-username-and-password

Local DNS
http://bencane.com/2013/10/29/managing-dns-locally-with-etchosts/

Ssh to vagrant machine ip address using:
username: vagrant
password: vagrant

$ ssh vagrant@192.168.100.101 
vagrant@192.168.100.101's password: 
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Tue May  3 02:58:13 2016 from 192.168.100.1

vagrant@precise64:~$ 

https://www.vagrantup.com/docs/networking/private_network.html

vagrant ssh-config command.
http://www.hashbangcode.com/blog/connecting-vagrant-box-without-vagrant-ssh-command

1. Get the vagrant ssh configuration using the following command. If there are multiple vagrant machines active then you will see multiple vagrant ssh configs.
$  vagrant ssh-config 

2. Now create the command line ssh command using the information from the vagrant ssh-config command output

From the above link:
However, what we are doing here is essentially using the local machine to route us to the correct machine based on it's port number. I still wanted to connect to the box via the IP address that I had set for it. This meant using the -o flag to pass in the extra SSH config parameters to the command.
So assuming that the virtual machine's IP address is 192.168.100.100 then you would connect to it in the following way.
ssh vagrant@192.168.100.100 -i /your/user/directory/.vagrant.d/insecure_private_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o IdentitiesOnly=yes
You can simplify this slightly by using your SSH config file to automatically add these parameters to your SSH call when you run it. This assumes the box IP address is the same as above, but you can also include wildcards in the Host header to include a number of Vagrant boxes (based on their IP address).
1
2
3
4
5
6
7
Host 192.168.100.100
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
  IdentitiesOnly yes
  User vagrant
  IdentityFile /your/user/directory/.vagrant.d/insecure_private_key
  PasswordAuthentication no
This allows you to connect to the box using the following command (without so many of the extra options present).
ssh vagrant@192.168.100.100

If you want to SSH directly to the Vagrant VM from a remote host (in the same LAN), the best and easiest way is to use Public Network (VirtualBox's Bridged networking mode).

An automated way to ssh...
https://github.com/puphpet/puphpet/issues/1253
If you want to avoid the password, the easiest way is to use the SSH config file output by vagrant. The trick is to login to default not vagrant@127.0.0.1 or vagrant@localhost. This is because the config output by ssh-config is for a host called default.
# Write the ssh config to a file
vagrant ssh-config > ssh.config
# Tell ssh to use this config file instead of your user config file (if it exists)
ssh -F ssh.config default
Alternatively:

ssh -F ssh.config vagrant@192.168.100.101
password: vagrant