Cheat Sheet Example Vagrantfile

Cheat Sheet Example Vagrantfile

Cheat Sheet Terms and Definitions Example Vagrantfile - CentOS 7 with Apache Box A prepackaged Vagrant environment that is the same on any computer in which it is provisioned. # The $samplescript variable uses Ruby to feed in a script that runs upon # provisioning: Provider The underlying system that manages the virtual machines, such as VirtualBox and Docker. $samplescript = <<SCRIPT Provisioner Systems that allow you to install software yum install -y httpd and otherwise configure guest machines, such as Chef and systemctl enable httpd Puppet. systemctl start httpd Vagrantfile A single file used to define the desired SCRIPT Vagrant environment; written in Ruby. # Define Vagrant configuration version (2): Vagrant.configure(2) do |config| Commands # Define what box to use (CentOS 7): vagrant init config.vm.box = "centos/7" >> Initialize the directory as a Vagrant environment; creates Vagrantfile. # Define hostname (myhost); most useful for environments with multiple guests: vagrant box add <boxname> >> Add a Vagrant box to to environment. config.vm.hostname = "myhost" vagrant up >> Create and configure the guest machine(s) defined in the Vagrantfile. # Configure private network IP address: vagrant ssh config.vm.network "private_network", ip: "192.168.50.10" >> SSH into a guest machine; include hostname in multi-machine environments. vagrant halt # Sync files between local src/ folder and guest /var/www/html folder: >> Attempt a graceful shutdown of the guest machine(s) config.vm.synced_folder "src/", "/var/www/html" vagrant suspend >> Suspend the machine(s) in its current state; does not shut down machine(s). # Provision guest with $samplescript variable; uses shell scripting: vagrant resume >> Start stopped guest machine(s), whether halted or suspended. config.vm.provision "shell", inline: $samplescript vagrant reload # Set guest options for VirtualBox, including memory (1024), and CPU (2): >> Reboot guest machine; the same as running vagrant halt then vagrant resume. config.vm.provider "virtualbox" do |vb| vagrant status vb.memory = "1024" >> View state of machines managed by Vagrant vb.cpus = "2" vagrant destroy end >> Remove guest machine(s). end.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us