{"id":649,"date":"2021-11-14T22:30:11","date_gmt":"2021-11-15T03:30:11","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=649"},"modified":"2024-02-08T08:41:56","modified_gmt":"2024-02-08T13:41:56","slug":"provisioning-vagrant","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/provisioning-vagrant\/","title":{"rendered":"Provisioning vagrant"},"content":{"rendered":"\n<p>This article shows you how to provision your vagrant. We will start with a very simple dumb box and add features incrementally.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Prerequisites<\/h4>\n\n\n\n<p>You need to have virtualbox and vagrant installed on your system before following this article.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Basic box<\/h4>\n\n\n\n<p>Lets begin by creating the most basic vagrant box.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>create a directory somewhere e.g. mkdir ~\/meanbox<\/li><li>cd into the directory and run the command &#8220;vagrant init&#8221;<\/li><li>You should now see a file called VagrantFile. Replace its contents with the following<\/li><li>Run vagrant up<\/li><\/ol>\n\n\n\n<p>VagrantFile<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Vagrant.configure(2) do |config|    \n\n  # ubuntu 14.04\n  config.vm.box = \"ubuntu\/trusty64\"\n\n  # Provider-specific configuration so you can fine-tune various\n  # backing providers for Vagrant. These expose provider-specific options.\n  config.vm.provider \"virtualbox\" do |vb|\n    vb.memory = \"2048\"\n  end\nend\n<\/code><\/pre>\n\n\n\n<p>config.vm.box defines the box you want to install. Do you want to install Ubuntu 12.04, 14.04, CentOS, or other custom boxes. You can find the list of boxes at https:\/\/atlas.hashicorp.com\/boxes. In this example, I chose ubuntu\/trusty64 which is Ubuntu 14.04.<\/p>\n\n\n\n<p>config.vm.provider specifies the virtual machine software and allocated memory. In this example, we are have specified that we are using virtualbox and that we have allocated 2Gb memory to this virtual machine.<\/p>\n\n\n\n<p>Once the box is running, you can run &#8220;vagrant ssh&#8221; command to log into the shell of the system.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">External Provisioning<\/h4>\n\n\n\n<p>We can call a shell script or Puppet, Chef, Ansible, or Docker code for provisioning. In this example, we will specify a private network, create a directory shared between host and guest machines, and provision from a shell script.<\/p>\n\n\n\n<p>Replace the contents of Vagrantfile with the following<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Vagrant.configure(2) do |config|\n\n  # ubuntu 14.04\n  config.vm.box = \"ubuntu\/trusty64\"\n\n  # check box for updates\n  config.vm.box_check_update = true\n\n  # shared folder between host and guest os\n  config.vm.synced_folder \"data\", \"\/var\/www\", :mount_options =&gt; &#91;\"dmode=777\", \"fmode=666\"]\n\n  # forwarded port mapping\n  config.vm.network \"private_network\", ip: \"192.168.20.20\"\n\n  # host name\n  config.vm.hostname = \"meanbox1\"\n\n  # Provider-specific configuration so you can fine-tune various\n  # backing providers for Vagrant. These expose provider-specific options.\n  config.vm.provider \"virtualbox\" do |vb|\n    vb.memory = \"2048\"\n  end\n\n  # Enable provisioning with a shell script. Additional provisioners such as\n  # Puppet, Chef, Ansible, Salt, and Docker are also available.\n  config.vm.provision \"shell\", path: \"provision.sh\"\nend\n<\/code><\/pre>\n\n\n\n<p>Create an empty directory called &#8220;data&#8221;.<\/p>\n\n\n\n<p>config.vm.synced_folder maps a directory between guest and host OS. The data directory can be access by your machine&#8217;s operating system so you can use all your software. Without mapping, you will be limited to software you have installed on your virtual machine and you will not have any nice GUI software.<\/p>\n\n\n\n<p>In this example, config.vm.network defines a private network with IP 192.168.20.20. Once you install Apache on your virtual machine, you will be able to access a site installed on it from the address in the browser.<\/p>\n\n\n\n<p>config.vm.provision is specifying that we will be using a shell script for provisioning and the file is located at provision.sh<\/p>\n\n\n\n<p>Create a file provision.sh and the following code to it. Set it to chmod 755.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\necho \"Provisioning VM...\\n\"\nsudo apt-get install git -y\n<\/code><\/pre>\n\n\n\n<p>This code will install git on the virtual machine. Run one of the following commands<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vagrant up --provision\nor\nvagrant reload --provision\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Practical Provisioning<\/h4>\n\n\n\n<p>So far we have only looked a simple examples. To build a powerful and useful box, you would need to do a lot more installation and configuration in your shell script. I would strongly recommend that you start from the script found at https:\/\/gist.github.com\/rrosiek\/8190550. It installs Apache, MySQL, PHP, phpMyAdmin, and many other useful tools. It is will help you get started faster and the code is a good example for beginners.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article shows you how to provision your vagrant. We will start with a very simple dumb box and add features incrementally. Prerequisites You need to have virtualbox and vagrant installed on your system before following this article. Basic box Lets begin by creating the most basic vagrant box. create a directory somewhere e.g. mkdir [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[512],"tags":[514],"class_list":["post-649","post","type-post","status-publish","format-standard","hentry","category-misc","tag-virtualization"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=649"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/649\/revisions"}],"predecessor-version":[{"id":650,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/649\/revisions\/650"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}