Add Libvirt support

Add support for Libvirt

Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
This commit is contained in:
Scott Lowe 2018-06-06 23:55:05 -06:00
parent f6460442bf
commit 38fe6805a4
4 changed files with 40 additions and 22 deletions

View file

@ -5,14 +5,10 @@
Vagrant.require_version '>= 1.6.0'
VAGRANTFILE_API_VERSION = '2'
# Explicitly specify the VMware provider (req'd for nested virtualization)
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion'
# Require 'yaml' module
require 'yaml'
# Read YAML file with VM details (box, CPU, RAM, IP addresses)
# Edit machines.yml to change VM configuration details
# Read YAML file with VM details (box, CPU, and RAM)
machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml'))
# Create and configure the VMs
@ -30,11 +26,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Don't check for box updates
srv.vm.box_check_update = false
# Specify the hostname of the VM
# Set machine's hostname
srv.vm.hostname = machine['name']
# Specify the Vagrant box to use (must use VMware box)
srv.vm.box = machine['vmw_box']
# Use VMware box by default
srv.vm.box = machine['box']['vmw']
# Configure default synced folder (disable by default)
if machine['sync_disabled'] != nil
@ -43,10 +39,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
srv.vm.synced_folder '.', '/vagrant', disabled: true
end #if machine['sync_disabled']
# Assign additional private network
if machine['ip_addr'] != nil
srv.vm.network 'private_network', ip: machine['ip_addr']
end # if machine['ip_addr']
# Iterate through networks as per settings in machines.yml
machine['nics'].each do |net|
if net['ip_addr'] == 'dhcp'
srv.vm.network net['type'], type: net['ip_addr']
else
srv.vm.network net['type'], ip: net['ip_addr']
end # if net['ip_addr']
end # machine['nics'].each
# Configure CPU & RAM per settings in machines.yml (Fusion)
srv.vm.provider 'vmware_fusion' do |vmw|
@ -57,10 +57,20 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
vmw.vmx['vhv.enable'] = 'TRUE'
end # srv.vm.provider 'vmware_fusion'
# Provision the VM with Ansible
config.vm.provision 'ansible' do |ansible|
ansible.playbook = 'provision.yml'
end # config.vm.provision
# Configure CPU & RAM per settings in machines.yml (Libvirt)
srv.vm.provider 'libvirt' do |lv,override|
lv.memory = machine['ram']
lv.cpus = machine['vcpu']
override.vm.box = machine['box']['lv']
# Enable nested virtualization (required for KVM)
lv.nested = true
end # srv.vm.provider 'libvirt'
end # config.vm.define
end # machines.each
# Provision the VM with Ansible
config.vm.provision 'ansible' do |ansible|
ansible.playbook = 'provision.yml'
end # config.vm.provision
end # Vagrant.configure

View file

@ -2,4 +2,4 @@
inventory = ./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
private_key_file = ~/.vagrant.d/insecure_private_key
remote_user = vagrant
host_key_checking = False
host_key_checking = False

View file

@ -1,7 +1,11 @@
---
- name: "kvm-01"
vmw_box: "bento/ubuntu-14.04"
- box:
vmw: "bento/ubuntu-16.04"
lv: "generic/ubuntu1604"
name: "kvm-01"
nics:
- type: "private_network"
ip_addr: "dhcp"
ram: "1024"
sync_disabled: true
vcpu: "1"
ip_addr: "192.168.100.100"
nested: true

View file

@ -1,9 +1,13 @@
---
- hosts: "all"
sudo: "yes"
become: "yes"
remote_user: "vagrant"
gather_facts: false
tasks:
- name: "Install Python 2"
raw: "apt-get -y -q install python"
- name: "Install KVM and Libvirt"
apt:
state: "present"