Shutdown, Status, Startup, Authentication
In order to get the current configuration virtual boxes on our directory, we can use the get status command. This command will show us the hypervisor which the box is using, the name and in which state it is:
Get status
E:\Virtuals\Ainsible>vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`.
After we have found the status and verified that the machine is working, we can connect to it via SSH. Vagrant is using its own username/password for monitor and connection to the machine. Therefore, even if you cannot connect to the SSH, that doesn't mean that the machine doesn't work or it isn't accessible from other sites :)
Connect to the machine
E:\Virtuals\Ainsible>vagrant ssh default [vagrant@localhost ~]$ [vagrant@localhost ~]$ [vagrant@localhost ~]$ [vagrant@localhost ~]$ [vagrant@localhost ~]$ ls -alrt total 12 -rw-r--r--. 1 vagrant vagrant 231 Apr 11 00:53 .bashrc -rw-r--r--. 1 vagrant vagrant 193 Apr 11 00:53 .bash_profile -rw-r--r--. 1 vagrant vagrant 18 Apr 11 00:53 .bash_logout drwxr-xr-x. 3 root root 21 May 12 18:54 .. drwx------. 3 vagrant vagrant 74 May 12 18:54 . drwx------. 2 vagrant vagrant 29 Aug 13 13:52 .ssh
We can shutdown the machine if it is not longer needed. Vagrant, will just send the shutdown instructions to the hypervisor: VMware or VirtualBox and proceed with disconnecting all sessions:
Shutdown
E:\Virtuals\Ainsible>vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`. E:\Virtuals\Ainsible>vagrant halt default ==> default: Attempting graceful shutdown of VM... E:\Virtuals\Ainsible>
As you saw, we had to connect to the machine using vagrant. What about if I want to connect using ssh client ? Well I will have to use username and a password, something which I don't have yet :) So in order for me to connect via ssh, I have to set up the configuration in the vangrant file as follows:
Example Authentication
config.ssh.username = 'root' config.ssh.password = 'vagrant' config.ssh.insert_key = 'true'
* P.S. By default, vagrant is using: vagrant/vagrant as a username and password for monitoring and handling of the VM. Therefore, if you will change the password, be sure to re-upload the new ssh keys to the vm.
Of course, once the changes are done, we can start the machine from the command line again as follows:
Startup
E:\Virtuals\Ainsible>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'centos/7' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: password ==> default: Machine booted and ready!
Memory, Network
In order to configure network and Memory, we have to again shutdown our virtual box and edit the configuration as follows:
Memory Config
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 = "1534" end
Since the memory is linked with the RAM of the host machine, do not add excessive memory, or you will slow your host machine. In order to add additional network adapters, we have to again change the configuration the box configuration:
Network Config
config.vm.box = "centos/7" config.ssh.username = 'vagrant' config.ssh.password = 'vagrant' config.ssh.insert_key = 'false' config.vm.network "private_network", ip: "192.168.10.2" config.vm.network "public_network" <- Will take the IP from the bridged net, you will see it as additional host on your network. config.ssh.forward_agent = true
Configure Guess plugin
Guess plugin installation
vagrant plugin install vagrant-vbguest
We can also list plugins as follows:
List vagrant plugin
C:\Learning\Oracle19c> vagrant plugin list vagrant-puppet-install (6.0.1, global) - Version Constraint: > 0 vagrant-vbguest (0.21.0, global) - Version Constraint: 0.21