Skip to content

Instantly share code, notes, and snippets.

@miticojo
Last active April 4, 2017 07:33
Show Gist options
  • Save miticojo/446119ea0bcf2062339ad519fb9abab5 to your computer and use it in GitHub Desktop.
Save miticojo/446119ea0bcf2062339ad519fb9abab5 to your computer and use it in GitHub Desktop.
Vagrant setup for Linux CentOS/Fedora/Debian/Ubuntu, OSX and Windows
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Start-Transcript -path $scriptPath\Win10_Ansible_Development_PC_Install.log -append
# elevate privileges to administrator to install chocolatey and other needed packages
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
# Configure PowerShell Execution Policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
# Install Chocolatey
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
# Install the required apps
choco install git -y
choco install virtualbox -y
choco install vagrant -y
choco install vagrant-manager -y
choco install atom -y
# Refresh env variables to get new PATH
refreshenv
# Install Atom plugins
apm install git-control
apm install language-ansible
apm install linter-ansible-syntax
apm install autocomplete-ansible
vagrant box add centos/7 --provider virtualbox
Stop-Transcript
#!/usr/bin/env bash
setup_macos(){
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew cask install virtualbox
brew cask install vagrant
}
setup_linux_fedora(){
sudo dnf install -y libxslt-devel libxml2-devel libvirt-devel \
libguestfs-tools-c ruby-devel gcc qemu libvirt libvirt-devel ruby-devel gcc
sudo dnf install -y vagrant vagrant-libvirt vagrant-libvirt-doc vagrant-lxc
vagrant plugin install vagrant-libvirt
}
setup_linux_centos_rel(){
sudo yum install -y libxslt-devel libxml2-devel libvirt-devel \
libguestfs-tools-c ruby-devel gcc qemu libvirt libvirt-devel ruby-devel gcc qemu-kvm
sudo yum install -y https://releases.hashicorp.com/vagrant/1.9.1/vagrant_1.9.1_x86_64.rpm
vagrant plugin install vagrant-libvirt
}
setup_linux_deb_ubuntu(){
sudo apt-get build-dep -y vagrant ruby-libvirt
sudo apt-get install -y qemu libvirt-bin ebtables dnsmasq
sudo apt-get install -y libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
vagrant plugin install vagrant-libvirt
}
select_linux(){
OS=$(uname -s)
VER=$(uname -r)
# Look for lsb_release in path
LSB_REL=$(which lsb_release 2>/dev/null)
if [[ $OS == Linux ]]; then
# If lsb_release is executable set the DIST and VER
if [[ -f /etc/redhat-release ]]; then
DIST=$(sed 's/ release.*//' /etc/redhat-release)
VER=$(sed 's/.*release\ //' /etc/redhat-release | sed 's/\ .*//')
CODENAME=$(sed 's/.*(//' /etc/redhat-release | sed 's/)//')
elif [[ -f /etc/SuSE-release ]]; then
DIST=$(head -1 suse | awk '{print $1}')
VER=$(awk '/VERSION/ {print $3}' /etc/SuSE-release)
CODENAME=$(awk '/CODENAME/ {print $3}' /etc/SuSE-release)
elif [[ -f /etc/arch-release ]]; then
DIST="Arch Linux"
VER=""
# Last time full system upgrade ran
# Can take a while to parse log (depending on log size)
#VER=$(grep 'starting full system upgrade' /var/log/pacman.log | tail -1 | sed 's/\[//' | sed 's/ .*//')
elif [[ -x $LSB_REL ]]; then
DIST=$($LSB_REL -is)
VER=$($LSB_REL -rs)
CODENAME=$($LSB_REL -cs)
elif [[ -f /etc/lsb-release ]]; then
DIST=$(grep 'DISTRIB_ID' /etc/lsb-release | cut -d"=" -f2)
VER=$(grep 'DISTRIB_RELEASE' /etc/lsb-release | cut -d"=" -f2)
CODENAME=$(grep 'DISTRIB_RELEASE' /etc/lsb-release | cut -d"=" -f2)
elif [[ -f /etc/debian_version ]]; then
DIST="Debian"
read VER < /etc/debian_version
else
DIST="${OS}"
fi
# Exceptions
# RHEL uses multiple strings RedHatEnterpriseWS (4.x), RedHatEnterpriseServer (5.x, 6.x)
if [[ $DIST =~ RedHatEnterprise ]] || [[ $DIST =~ "Red Hat Enterprise Linux Server" ]]; then
DIST="RHEL"
fi
OSSTR="${DIST}"
else
OSSTR="$OS"
fi
case "$OSSTR" in
Fedora*) setup_linux_fedora ;;
CentOS*) setup_linux_centos_rel ;;
Debian*) setup_linux_deb_ubuntu ;;
Ubuntu*) setup_linux_deb_ubuntu ;;
*) echo "unknown: $OSSTR" ;;
esac
}
case "$OSTYPE" in
solaris*) echo "SOLARIS is not supported here" ;;
darwin*) setup_macos ;;
linux*) select_linux ;;
bsd*) echo "BSD is not supported here" ;;
*) echo "unknown: $OSTYPE" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment