| name | devops-vagrant-file-creator |
| description | Expert assistant for creating and optimizing Vagrantfile configurations. Uses a deep knowledge base of Vagrant providers, networking, and provisioning. Trigger this skill whenever the user talks about "vagrant", "Vagrantfile", "virtual machine", "provision vm", "dev environment", or "local server". |
| license | MIT |
| compatibility | Requires Vagrant >=2.3.0 |
Vagrant File Creator
Generate production-ready Vagrantfile configurations using Ruby best practices and the comprehensive Vagrant knowledge base.
Core Capabilities
- Generate
Vagrantfile from scratch based on user requirements
- Validate and optimize existing Vagrantfiles
- Support multiple providers: VirtualBox (default), Docker, Hyper-V, VMware
- Configure networking: port forwarding, private/public networks, static IPs
- Add provisioners: Shell scripts, Ansible, Docker, Puppet, Chef
- Multi-machine setups for cluster environments
- Synced folders and shared directories
Workflow
1. Analyze User Request
Check if the request contains sufficient detail:
- Base OS/Box: e.g., ubuntu/focal, bento/ubuntu-22.04, centos/stream8
- Provider: VirtualBox (default), docker, vmware_fusion, hyperv
- Resources: CPU cores, memory (MB), disk size
- Networking: Port forwarding, private network, public network
- Provisioning: Shell scripts, Ansible playbooks, Docker installation
- Synced Folders: Host-to-guest directory mapping
2. Clarify Ambiguities
If the request lacks details, use the question tool to ask:
- Base Box: "Which base box would you like to use? (e.g., ubuntu/focal, bento/debian-11)"
- Provider: "Which provider? (default: VirtualBox) - Options: docker, vmware_fusion, hyperv"
- Resources: "How much memory (MB) and CPU cores? (default: 1024MB, 2 CPUs)"
- Networking: "Do you need port forwarding or a private network?"
- Provisioning: "Should I add any provisioners? (e.g., install Docker, run shell script)"
3. Consult Knowledge Base
Reference files in reference/ directory:
vagrantfile/index.mdx - Vagrantfile syntax and load order
providers/ - Provider-specific configurations
networking/ - Network configuration options
provisioning/ - Provisioner setups
synced-folders/ - Folder sharing options
multi-machine.mdx - Multi-VM configurations
4. Generate Vagrantfile
Output a complete, well-commented Vagrantfile following this structure:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 2
end
end
Templates
Basic Ubuntu VM (Default)
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 2
vb.name = "dev-machine"
end
end
Docker Development Environment
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
config.vm.provider "docker" do |d|
d.image = "ubuntu:22.04"
d.has_ssh = true
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y docker.io docker-compose
SHELL
end
Multi-Machine Cluster
Vagrant.configure("2") do |config|
config.vm.define "master" do |master|
master.vm.box = "ubuntu/focal"
master.vm.hostname = "master"
master.vm.network "private_network", ip: "192.168.50.10"
master.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
end
(1..2).each do |i|
config.vm.define "worker-#{i}" do |worker|
worker.vm.box = "ubuntu/focal"
worker.vm.hostname = "worker-#{i}"
worker.vm.network "private_network", ip: "192.168.50.#{10 + i}"
worker.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 1
end
end
end
end
Best Practices
- Always use version control: Vagrantfile should be committed to git
- Pin box versions: Use
config.vm.box_version for reproducibility
- Use private networks for multi-machine setups
- Add meaningful VM names via provider configuration
- Comment provisioners explaining what they install
- Use external scripts for complex provisioning via
path: "scripts/setup.sh"
Common Box Names
| OS | Box Name |
|---|
| Ubuntu 22.04 | ubuntu/jammy64 |
| Ubuntu 20.04 | ubuntu/focal64 |
| Debian 11 | debian/bullseye64 |
| CentOS Stream 9 | centos/stream9 |
| Fedora 38 | fedora/38-cloud-base |
Output Format
When generating a Vagrantfile:
- Display the complete file content in a code block
- Add usage instructions:
vagrant up - Start the VM
vagrant ssh - Connect to the VM
vagrant halt - Stop the VM
vagrant destroy - Delete the VM
- Note any required plugins (e.g.,
vagrant plugin install vagrant-docker)