How often do you have to develop and launch an application locally and persist in looking for problems, because in production, an application does not behave exactly the way you want it? And how often do they send you tickets to solve a problem in the application, although in fact the problem is in the incompatibility of versions of different applications? And how long do you have to wait for the virtual machine when there are not enough local machine resources to launch the new version of the application? For us, these issues were quite sick, and we broke thousands of copies in disputes, trying to solve them. Practice shows that Vagrant can become one of the options for solving these problems. 
# -*- 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| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "precise64" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. # config.vm.box_url = "http://domain.com/path/to/above.box" config.vm.box_url = "http://files.vagrantup.com/precise64.box" # 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. # config.vm.network :forwarded_port, guest: 3000, host: 3000 # 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 # If true, then any SSH connections made will enable agent forwarding. # Default value: false config.ssh.forward_agent = true ### Define VM for RabbitMQ config.vm.define "rmq", primary: true do |rmq| # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # rmq.vm.provider :virtualbox do |vb| # Don't boot with headless mode vb.gui = false # Use VBoxManage to customize the VM. For example to change memory: vb.customize ["modifyvm", :id, "--memory", "1024"] end # Networking options rmq.vm.network :private_network, ip: "192.168.100.5" rmq.vm.hostname = "rmq.example.com" end end rmq.vm.provision :puppet do |puppet| puppet.manifests_path = "./vagrant.d/manifests" puppet.manifest_file = "site-rmq.pp" puppet.module_path = "./vagrant.d/modules" puppet.options = "--fileserver=/vagrant/vagrant.d/fileserver.conf --verbose --debug" end # Enable shell provisioning config.vm.provision "shell", path: "./vagrant.d/pre-puppet.sh" #!/bin/bash # This script installs modules for puppet standalone echo "[Info] Running pre-puppet.sh for install modules" if [ "x$(dpkg -l | grep -E '^ii\s+git\s')" == "x" ] then echo "[Info] Installing git" apt-get -y install git || (echo "[Error] Cant install git" && exit 0) else echo "[Info] git already is installed, skipping" fi if [ "x$(gem list librarian-puppet|grep -v LOCAL)" == "x" ] then echo "[Info] Installing librarian-puppet" gem install librarian-puppet || (echo "[Error] Cant install librarian-puppet" && exit 0) else echo "[Info] librarian-puppet already is installed, skipping" fi if [ ! -e Puppetfile ] then cat > Puppetfile << EOF #!/usr/bin/env ruby #^syntax detection # Warning! # Do not edit this file, check pre-puppet.sh script! # forge "http://forge.puppetlabs.com" # use dependencies defined in Modulefile #modulefile mod 'puppetlabs/rabbitmq' mod 'saz/timezone' mod 'saz/locales' mod 'jpuppet/java-git', :git => "git://github.com/jpuppet/java.git" mod 'jfryman/nginx' EOF fi mkdir -p /vagrant/vagrant.d/modules echo "[Info] Installing puppet modules" librarian-puppet install --path=/vagrant/vagrant.d/modules/ || (echo "[Error] Cant install modules" && exit) rm Puppetfile* # Ugly hack for java cp -r /vagrant/vagrant.d/modules/java-git/modules/java /vagrant/vagrant.d/modules exit 0 # -*- 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| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "precise64" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. # config.vm.box_url = "http://domain.com/path/to/above.box" config.vm.box_url = "http://files.vagrantup.com/precise64.box" # 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. # config.vm.network :forwarded_port, guest: 3000, host: 3000 # 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 # If true, then any SSH connections made will enable agent forwarding. # Default value: false config.ssh.forward_agent = true # Enable shell provisioning config.vm.provision "shell", path: "./vagrant.d/pre-puppet.sh" ### Define VM for RabbitMQ config.vm.define "rmq", primary: true do |rmq| # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # rmq.vm.provider :virtualbox do |vb| # Don't boot with headless mode vb.gui = false # Use VBoxManage to customize the VM. For example to change memory: vb.customize ["modifyvm", :id, "--memory", "1024"] end # Networking options rmq.vm.network :private_network, ip: "192.168.100.5" rmq.vm.hostname = "rmq.example.com" # Enable provisioning with Puppet stand alone. Puppet manifests # are contained in a directory path relative to this Vagrantfile. # You will need to create the manifests directory and a manifest in # the file base.pp in the manifests_path directory. # rmq.vm.provision :puppet do |puppet| puppet.manifests_path = "./vagrant.d/manifests" puppet.manifest_file = "site-rmq.pp" puppet.module_path = "./vagrant.d/modules" puppet.options = "--fileserver=/vagrant/vagrant.d/fileserver.conf --verbose --debug" end end end # # This manifest describes development environment # RabbitMQ-server # class { 'timezone': timezone => 'Europe/Moscow', } class { 'locales': locales => ['ru_RU.UTF-8 UTF-8'], } # apt-get update # --------------------------------------- class apt_install { exec {'update': command => 'apt-get update', path => '/usr/bin', timeout => 0, } -> package {[ 'vim', ]: ensure => installed, } } # RabbitMQ service class rabbitmq_install { class { '::rabbitmq': service_manage => false, port => '5672', delete_guest_user => true, } rabbitmq_user { 'developer': admin => true, password => 'Password', } rabbitmq_vhost { 'habr': ensure => present, } rabbitmq_user_permissions { 'developer@habr': configure_permission => '.*', read_permission => '.*', write_permission => '.*', } rabbitmq_plugin {'rabbitmq_management': ensure => present, } } class java_install { class { "java": version => "1.7", jdk => true, jre => true, sources => false, javadoc => false, set_as_default => true, export_path => false, vendor => "oracle", } } # Include classes include apt_install include timezone include locales include rabbitmq_install include java_install vagrant up vagrant ssh > vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) * Documentation: https://help.ubuntu.com/ Welcome to your Vagrant-built virtual machine. Last login: Sat May 17 12:28:08 2014 from 10.0.2.2 vagrant@rmq:~$ java -version java version "1.7.0_55" Java(TM) SE Runtime Environment (build 1.7.0_55-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode) 
Source: https://habr.com/ru/post/225305/
All Articles