Skip to content

Instantly share code, notes, and snippets.

@youcefmegoura
Created April 11, 2026 09:20
Show Gist options
  • Select an option

  • Save youcefmegoura/1b9e371045197fa72194fb50f3601482 to your computer and use it in GitHub Desktop.

Select an option

Save youcefmegoura/1b9e371045197fa72194fb50f3601482 to your computer and use it in GitHub Desktop.
Vagrant file to use Ubuntu preconfigured with all DevOps tools
load 'variables.rb'
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64"
config.vm.box_version = "20241002.0.0"
config.vm.synced_folder ".", "/vagrant"
config.vm.hostname = "ubuntu-vm"
config.vm.network "public_network",
type: "static",
bridge: "Intel(R) Wi-Fi 6E AX211 160MHz",
ip: "192.168.100.100",
netmask: "255.255.255.0"
config.vm.provision "shell", run: "always", inline: <<-SHELL
ip route del default via 10.0.2.2 dev enp0s3 2>/dev/null || true
ip route add default via 192.168.100.1 dev enp0s8 2>/dev/null || true
SHELL
config.vm.provider "virtualbox" do |vb|
vb.memory = "8192"
vb.cpus = 4
end
# Provision SSH keys
config.vm.provision "file", source: "~/.ssh/id_ed25519", destination: "/home/vagrant/.ssh/id_ed25519"
config.vm.provision "file", source: "~/.ssh/id_ed25519.pub", destination: "/home/vagrant/.ssh/id_ed25519.pub"
# Provision script
config.vm.provision "shell", inline: <<-SHELL
# Disable firewall
sudo ufw disable
# Update package list
sudo apt-get update
# Install Python3 (usually pre-installed, but ensure)
sudo apt-get install -y python3 python3-pip
# Install tree
if ! command -v tree &> /dev/null; then
sudo apt-get install -y tree
fi
# Install zsh and oh-my-zsh
if ! command -v zsh &> /dev/null; then
sudo apt-get install -y zsh git curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
chsh -s $(which zsh) vagrant
fi
# Install Ansible
if ! command -v ansible &> /dev/null; then
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt-get install -y software-properties-common gnupg
sudo apt-get install -y ansible
fi
# Install Terraform (latest from HashiCorp repo)
if ! command -v terraform &> /dev/null; then
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt update
sudo apt install -y terraform
fi
# Install AWS CLI v2 (latest)
if ! command -v aws &> /dev/null; then
sudo apt-get install -y unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
rm -rf aws awscliv2.zip
fi
# Set up AWS credentials
if [ ! -f /home/vagrant/.aws/credentials ]; then
mkdir -p /home/vagrant/.aws
cat <<EOT > /home/vagrant/.aws/credentials
[default]
aws_access_key_id = #{AWS_ACCESS_KEY_ID}
aws_secret_access_key = #{AWS_SECRET_ACCESS_KEY}
EOT
cat <<EOT > /home/vagrant/.aws/config
[default]
region = #{AWS_REGION}
output = json
EOT
chown -R vagrant:vagrant /home/vagrant/.aws
fi
# Install Docker
if ! dpkg -l | grep -q docker.io; then
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker vagrant
fi
# Install lazydocker
if ! command -v lazydocker &> /dev/null; then
curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash
fi
# Install kubectl (latest)
if ! command -v kubectl &> /dev/null; then
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo chmod +x kubectl
sudo mv kubectl /usr/local/bin/
fi
# Install Helm (latest)
if ! command -v helm &> /dev/null; then
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4
chmod 700 get_helm.sh
./get_helm.sh
rm get_helm.sh
fi
# Install k9s (latest)
if ! command -v k9s &> /dev/null; then
curl -L https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_amd64.tar.gz -o k9s.tar.gz
tar -xzf k9s.tar.gz
sudo mv k9s /usr/local/bin/
rm k9s.tar.gz
fi
# Install kops (latest)
if ! command -v kops &> /dev/null; then
sudo apt-get install -y jq
curl -Lo kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
sudo chmod +x kops
sudo mv kops /usr/local/bin/kops
fi
# Install k3s (latest)
if ! command -v k3s &> /dev/null; then
curl -sfL https://get.k3s.io | sh -s - server --bind-address=0.0.0.0 --tls-san=192.168.100.100
sudo chmod -R +r /etc/rancher/k3s/
fi
# Set up SSH keys
if [ -f /home/vagrant/.ssh/id_ed25519 ]; then
sudo chown vagrant:vagrant /home/vagrant/.ssh/id_ed25519*
chmod 600 /home/vagrant/.ssh/id_ed25519
chmod 644 /home/vagrant/.ssh/id_ed25519.pub
fi
# Git configuration
if [ -z "$(git config --global user.name)" ]; then
git config --global user.name "#{GIT_USER_NAME}"
fi
if [ -z "$(git config --global user.email)" ]; then
git config --global user.email "#{GIT_USER_EMAIL}"
fi
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment