Created
December 27, 2016 14:11
-
-
Save NickMRamirez/79368f0d3bb073f7781d7d6e29d72dc6 to your computer and use it in GitHub Desktop.
Helper functions for using Vagrant with VirtualBox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------ | |
# HELPER FUNCTIONS | |
# ------------------------------------------------------------------------ | |
def create_disk(node, drives) | |
node.vm.provider "virtualbox" do |vb| | |
unless File.exist?(File.join(".\\temp\\", node.vm.hostname, "#{drives[0][:drive_label]}.vdi")) | |
vb.customize ['storagectl', :id, '--name', 'Storage2', '--add', 'sata', '--controller', 'IntelAhci', '--portcount', '10'] | |
end | |
drives.each do |drive| | |
diskname = File.join(".\\temp\\", node.vm.hostname, "#{drive[:drive_label]}.vdi") | |
unless File.exist?(diskname) | |
vb.customize ['createhd', '--filename', diskname, '--format', 'VDI', '--size', drive[:size_gb] * 1024] | |
vb.customize ['storageattach', :id, '--storagectl', 'Storage2', '--port', drive[:port], '--device', 0, '--type', 'hdd', '--medium', diskname] | |
end | |
end | |
end | |
end | |
def format_disk(drive) | |
return %Q( | |
Write-Host "Checking if drive #{drive[:drive_letter]} exists..." | |
if ((Test-Path '#{drive[:drive_letter]}:') -eq $FALSE) | |
{ | |
Write-Host "Drive #{drive[:drive_letter]} does not exist. Creating..." | |
Get-Disk | where Number -eq #{drive[:port]} | | |
Initialize-Disk -PartitionStyle MBR -PassThru | | |
New-Partition -DriveLetter #{drive[:drive_letter]} -UseMaximumSize | | |
Format-Volume -FileSystem NTFS -NewFileSystemLabel '#{drive[:drive_label]}' -Confirm:$false | |
} | |
) | |
end | |
windows_puppet_agent_install_cmd = %Q( | |
$OUTPUT_DIR = "C:\\puppet-agent-1.3.2-x64.msi" | |
if (Test-Path $OUTPUT_DIR) | |
{ | |
Write-Host "Puppet already downloaded and should be installed." | |
} | |
else | |
{ | |
$PUPPET_AGENT_DOWNLOAD_URL = "https://pm.puppetlabs.com/puppet-agent/2015.3.0/1.3.2/repos/windows/puppet-agent-1.3.2-x64.msi?_ga=1.250380614.1504919296.1450823152" | |
Write-Host "Downloading Puppet Agent..." | |
Invoke-WebRequest $PUPPET_AGENT_DOWNLOAD_URL -OutFile $OUTPUT_DIR | |
msiexec /norestart /qn /i $OUTPUT_DIR | |
Write-Host "Waiting for Puppet Agent to be installed..." | |
Start-Sleep -s 60 | |
} | |
) | |
centos_puppet_agent_install_cmd = %Q( | |
if ! rpm -qa | grep -qw puppet; then | |
echo "Installing Puppet Agent on node..." | |
sudo rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm | |
sudo yum install puppet -y | |
echo "Waiting for Puppet Agent to be installed..." | |
sleep 2m | |
else | |
echo "Puppet already downloaded and should be installed." | |
fi | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: