From 684f291f41fb93b5a34deef46c75535bf27400b7 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Wed, 21 Sep 2016 01:29:12 -0600 Subject: [PATCH] Ensure consistency across learning environments Modify YAML data files and Vagrantfile for various learning environments to ensure greater consistency and reduce technical debt --- photon-ansible/Vagrantfile | 33 +++++++++++++++++---------------- photon-ansible/machines.yml | 5 +++-- photon-cloudinit/Vagrantfile | 9 +++++---- photon-cloudinit/machines.yml | 6 +++--- photon/Vagrantfile | 9 +++++---- photon/machines.yml | 10 +++++----- 6 files changed, 38 insertions(+), 34 deletions(-) diff --git a/photon-ansible/Vagrantfile b/photon-ansible/Vagrantfile index 54f4095..5672875 100644 --- a/photon-ansible/Vagrantfile +++ b/photon-ansible/Vagrantfile @@ -1,17 +1,15 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# Specify Vagrant version, Vagrant API version, and desired clone location +# Specify minimum Vagrant version and Vagrant API version Vagrant.require_version '>= 1.6.0' VAGRANTFILE_API_VERSION = '2' -ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion' -ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' -#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' # Require 'yaml' module require 'yaml' # Read YAML file with VM details (box, CPU, and RAM) +# Edit machines.yml to change VM configuration details machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml')) # Create and configure the VMs @@ -22,19 +20,21 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Iterate through entries in YAML file to create VMs machines.each do |machine| + + # Configure the VMs per details in machines.yml config.vm.define machine['name'] do |srv| # Don't check for box updates srv.vm.box_check_update = false - srv.vm.hostname = machine['name'] - srv.vm.box = machine['box'] - # Configure default synced folder (disable by default) - if machine['sync_disabled'] != nil - srv.vm.synced_folder '.', '/vagrant', disabled: machine['sync_disabled'] - else - srv.vm.synced_folder '.', '/vagrant', disabled: true - end #if machine['sync_disabled'] + # Specify the hostname of the VM + srv.vm.hostname = machine['name'] + + # Specify the Vagrant box to use (use VMware box by default) + srv.vm.box = machine['vmw_box'] + + # Disable default synced folder (not supported with Photon) + srv.vm.synced_folder '.', '/vagrant', disabled: true # Assign additional private network if machine['ip_addr'] != nil @@ -43,16 +43,17 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Configure CPU & RAM per settings in machines.yml (Fusion) # Nested virt not included because not supported with Photon - srv.vm.provider :vmware_fusion do |vmw| + srv.vm.provider 'vmware_fusion' do |vmw| vmw.vmx['memsize'] = machine['ram'] vmw.vmx['numvcpus'] = machine['vcpu'] - end # srv.vm.provider vmware_fusion + end # srv.vm.provider 'vmware_fusion' # Configure CPU & RAM per settings in machines.yml (VirtualBox) - srv.vm.provider :virtualbox do |vb| + srv.vm.provider 'virtualbox' do |vb, override| vb.memory = machine['ram'] vb.cpus = machine['vcpu'] - end # srv.vm.provider virtualbox + override.vm.box = machine['vb_box'] + end # srv.vm.provider 'virtualbox' end # config.vm.define # Provision the VM with Ansible diff --git a/photon-ansible/machines.yml b/photon-ansible/machines.yml index 3c4e18a..3edca12 100644 --- a/photon-ansible/machines.yml +++ b/photon-ansible/machines.yml @@ -1,5 +1,6 @@ --- -- name: "photon" - box: "vmware/photon" +- name: "photon-01" + vmw_box: "vmware/photon" + vb_box: "vmware/photon" ram: "512" vcpu: "1" diff --git a/photon-cloudinit/Vagrantfile b/photon-cloudinit/Vagrantfile index 6ae7750..bac3bd6 100644 --- a/photon-cloudinit/Vagrantfile +++ b/photon-cloudinit/Vagrantfile @@ -1,7 +1,7 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# Specify Vagrant version, Vagrant API version, and Vagrant clone location +# Specify minimum Vagrant version and Vagrant API version Vagrant.require_version '>= 1.6.0' VAGRANTFILE_API_VERSION = '2' @@ -9,7 +9,7 @@ VAGRANTFILE_API_VERSION = '2' require 'yaml' # Read YAML file with VM details (box, CPU, and RAM) -# Edit servers.yml to change VM configuration details +# Edit machines.yml to change VM configuration details machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml')) # Look for user-data and meta-data files in same directory @@ -40,13 +40,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Disable default synced folder (not supported with Photon) srv.vm.synced_folder '.', '/vagrant', disabled: true - # Configure VMs with RAM and CPUs per machines.yml (Fusion) + # Configure CPU & RAM per settings in machines.yml (Fusion) + # Nested virt not included because not supported with Photon srv.vm.provider 'vmware_fusion' do |vmw| vmw.vmx['memsize'] = machine['ram'] vmw.vmx['numvcpus'] = machine['vcpu'] end # srv.vm.provider 'vmware_fusion' - # Configure VMs with RAM and CPU per machines.yml (VirtualBox) + # Configure CPU & RAM per settings in machines.yml (VirtualBox) srv.vm.provider 'virtualbox' do |vb, override| vb.memory = machine['ram'] vb.cpus = machine['vcpu'] diff --git a/photon-cloudinit/machines.yml b/photon-cloudinit/machines.yml index bac8cf3..3edca12 100644 --- a/photon-cloudinit/machines.yml +++ b/photon-cloudinit/machines.yml @@ -1,6 +1,6 @@ --- -- name: photon-01 - vmw_box: vmware/photon - vb_box: vmware/photon +- name: "photon-01" + vmw_box: "vmware/photon" + vb_box: "vmware/photon" ram: "512" vcpu: "1" diff --git a/photon/Vagrantfile b/photon/Vagrantfile index 4ed7963..eab4448 100644 --- a/photon/Vagrantfile +++ b/photon/Vagrantfile @@ -1,7 +1,7 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# Specify Vagrant version, Vagrant API version, and Vagrant clone location +# Specify minimum Vagrant version and Vagrant API version Vagrant.require_version '>= 1.6.0' VAGRANTFILE_API_VERSION = '2' @@ -9,7 +9,7 @@ VAGRANTFILE_API_VERSION = '2' require 'yaml' # Read YAML file with VM details (box, CPU, and RAM) -# Edit servers.yml to change VM configuration details +# Edit machines.yml to change VM configuration details machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml')) # Create and configure the VMs @@ -36,13 +36,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Disable default synced folder (not supported with Photon) srv.vm.synced_folder '.', '/vagrant', disabled: true - # Configure VMs with RAM and CPUs per machines.yml (Fusion) + # Configure CPU & RAM per settings in machines.yml (Fusion) + # Nested virt not included because not supported with Photon srv.vm.provider 'vmware_fusion' do |vmw| vmw.vmx['memsize'] = machine['ram'] vmw.vmx['numvcpus'] = machine['vcpu'] end # srv.vm.provider 'vmware_fusion' - # Configure VMs with RAM and CPU per machines.yml (VirtualBox) + # Configure CPU & RAM per settings in machines.yml (VirtualBox) srv.vm.provider 'virtualbox' do |vb, override| vb.memory = machine['ram'] vb.cpus = machine['vcpu'] diff --git a/photon/machines.yml b/photon/machines.yml index 3b9829e..3edca12 100644 --- a/photon/machines.yml +++ b/photon/machines.yml @@ -1,6 +1,6 @@ --- -- name: photon-01 - vmw_box: vmware/photon - vb_box: vmware/photon - ram: 512 - vcpu: 1 +- name: "photon-01" + vmw_box: "vmware/photon" + vb_box: "vmware/photon" + ram: "512" + vcpu: "1"