# Self-check Questions for the 1st IBD lab ### 1. What will happen if you will start the vagrant machine without $vagrant init. Why? This initializes the current directory to be a Vagrant environment by creating an initial Vagrantfile if one does not already exist. If we start the the vagrant machine without $vagrant init, we will get warning: *A Vagrant environment or target machine is required to run this command. Run `vagrant init` to create a new Vagrant environment. Or, get an ID of a target machine from `vagrant global-status` to run this command on. A final option is to change to a directory with a Vagrantfile and to try again.~*~* So, that basically means that environment or target machine is not initialized and we can't bring it up until call $vagrant init. ### 2. To bring up the Vagrant virtual environment, you can use $vagrant up. What will happen after the command? This command creates and configures guest machines according to your Vagrantfile. ### 3. How do you access (login into) virtual machine created with vagrant? Using $vagrant connect NAME (or just $vagrant ssh VM_NAME (if there is mane machines)). We can connect also by: *--disable-static-ip* - The connect command will not spin up a small virtual machine to create a static IP you can access. When this flag is set, the only way to access the connection is to use the SOCKS proxy address outputted. *--static-ip IP* - Tells connect what static IP address to use for the virtual machine. By default, Vagrant connect will use an IP address that looks available in the 172.16.0.0/16 space. ### 4. What is a BOX in Vagrant? Boxes are the package format for Vagrant environments. A box can be used by anyone on any platform that Vagrant supports to bring up an identical working environment. The vagrant box utility provides all the functionality for managing boxes. The easiest way to use a box is to add a box from the publicly available catalog of Vagrant boxes. You can also add and share your own customized boxes on this website. ### 5. What is Provider in Vagrant? While Vagrant ships out of the box with support for VirtualBox, Hyper-V, and Docker, Vagrant has the ability to manage other types of machines as well. This is done by using other providers with Vagrant. Alternate providers can offer different features that make more sense in your use case. For example, if you are using Vagrant for any real work, VMware providers are recommended since they're well supported and generally more stable and performant than VirtualBox. Before you can use another provider, you must install it. Installation of other providers is done via the Vagrant plugin system. Once the provider is installed, usage is straightforward and simple, as you would expect with Vagrant. Read into the relevant subsections found in the navigation to the left for more information. ### 6. What is Provisioner in Vagrant? Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process. This is useful since boxes typically are not built perfectly for your use case. Of course, if you want to just use vagrant ssh and install the software by hand, that works. But by using the provisioning systems built-in to Vagrant, it automates the process so that it is repeatable. Most importantly, it requires no human interaction, so you can vagrant destroy and vagrant up and have a fully ready-to-go work environment with a single command. Powerful. Vagrant gives you multiple options for provisioning the machine, from simple shell scripts to more complex, industry-standard configuration management systems. ### 7. What is Vagrantfile? The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines. Vagrantfiles are called Vagrantfiles because the actual literal filename for the file is Vagrantfile (casing does not matter unless your file system is running in a strict case sensitive mode). The syntax of Vagrantfiles is Ruby, but knowledge of the Ruby programming language is not necessary to make modifications to the Vagrantfile, since it is mostly simple variable assignment. In fact, Ruby is not even the most popular community Vagrant is used within, which should help show you that despite not having Ruby knowledge, people are very successful with Vagrant. There are following possible configs: * The settings within *config.vm* modify the configuration of the machine that Vagrant manages. * The settings within *config.ssh* relate to configuring how Vagrant will access your machine over SSH. As with most Vagrant settings, the defaults are typically fine, but you can fine tune whatever you would like. * The settings within *config.vagrant* modify the behavior of Vagrant itself. ### 8. What are Synced Folders in Vagrant? These are the folders that allow to sync the folder of the host machine to the guest machine. By default the synced folder is the working directory, stored on the guest machine in `/vagrant`. It can be set using `config.vm.synced_folder "<dir on host machine>", "<dir on guest machine>"` in Vagrantfile ### 9. What is Multi-Machine environment in Vagrant? Vagrant is able to define and control multiple guest machines per Vagrantfile. This is known as a "multi-machine" environment. These machines are generally able to work together or are somehow associated with each other. Here are some use-cases people are using multi-machine environments for today: * Accurately modeling a multi-server production topology, such as separating a web and database server. * Modeling a distributed system and how they interact with each other. * Testing an interface, such as an API to a service component. * Disaster-case testing: machines dying, network partitions, slow networks, inconsistent world views, etc. ### 10. How do you define multiple machines in Vagrant? ``` Vagrant.configure("2") do |config| config.vm.provision "shell", inline: "echo Hello" config.vm.define "web" do |web| web.vm.box = "apache" end config.vm.define "db" do |db| db.vm.box = "mysql" end end ``` ### 11. What does `vagrant push` do? Vagrant is capable of deploying or "pushing" application code in the same directory as your Vagrantfile to a remote such as an FTP server. Basically, it's the same as `git push`, but before being able to perfrom `vagrant push`, one needs to define it in `Vagrantfile`. ``` config.push.define "ftp" do |push| push.host = "ftp.example.com" push.username = "..." # ... end ``` ### 12. What does `vagrant box list` do? This command lists all the boxes that are installed into Vagrant. ### 13. What does `vagrant box outdated` do? This command tells whether or not the box in the current Vagrant environment is outdated. If the `--global` flag is present, every installed box will be checked for updates. Also it shows the latest version available for the specific provider type, which may be different than the absolute latest version available. ### 14. What does `vagrant box prune` do? This command removes old versions of installed boxes. If the box is currently in use vagrant will ask for confirmation. ### 15. What does `vagrant box remove NAME` do? This command removes a box from Vagrant that matches the given name. ### 16. What does `vagrant box repackage` do? You use vagrant with a given box, again you will make change to the VM and you want to save those changes (software installed ...) as a new box, you will run vagrant repackage on this box, and it will create an updated version of this box so it can be used as starting box for new VM. ### 17. What does `vagrant box update` do? This command updates the box for the current Vagrant environment if there are updates available. The command can also update a specific box (outside of an active Vagrant environment), by specifying the `--box flag`. ### 18. What does `vagrant connect NAME` do? The connect command complements the share command by enabling access to shared environments. ### 19. What does `vagrant destroy NAME|ID` do? This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process. The equivalent one is `vagrant shutdown NAME|ID`