### Install Dependencies and Start Website (Node.js) Source: https://github.com/hashicorp/vagrant/blob/main/website/README.md Use these commands to install dependencies and start the Vagrant website locally if you have Node.js installed. Run `npm install` again if you pull new code. ```bash npm install npm start ``` -------------------------------- ### Run Vagrant with Bundle Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/installation/source.mdx Start Vagrant using the bundle exec command after installing dependencies. Warning messages are expected for source installations. ```shell bundle exec vagrant ``` -------------------------------- ### Initialize a New Environment with a Box Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/boxes/index.mdx Use the `vagrant init` command to initialize a new Vagrant environment with a specific box. This is the quickest way to get started with a new project. ```shell-session $ vagrant init hashicorp/bionic64 ``` -------------------------------- ### Prerelease Display Example Source: https://github.com/hashicorp/vagrant/blob/main/website/README.md An example of how prerelease information is displayed on the website, with placeholders for configurable parameters. ```html A {{ release candidate }} for {{ v1.0.0 }} is available! The release can be downloaded here. ``` -------------------------------- ### Initialize Vagrant Project with Local Install Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/installation/source.mdx Initialize a new Vagrant project using your locally installed Vagrant binary. Specify the full path to the generated 'exec/vagrant' file. ```shell /path/to/vagrant/exec/vagrant init -m hashicorp/bionic64 ``` -------------------------------- ### Create and start a VM Source: https://context7.com/hashicorp/vagrant/llms.txt Starts a Vagrant-managed machine. Downloads the box if needed, applies provisioning, and configures networking/folders. Use `--provision` to force provisioners, `--provider` to specify a provider, `--parallel` for parallel startup, or `--provision-with` to select specific provisioner types. ```shell $ vagrant up ``` ```shell $ vagrant up web ``` ```shell $ vagrant up --provision ``` ```shell $ vagrant up --provider vmware_desktop ``` ```shell $ vagrant up --parallel ``` ```shell $ vagrant up --provision-with shell,ansible ``` -------------------------------- ### Ansible Playbook Example Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/ansible_intro.mdx A sample Ansible playbook to install and restart the NTP daemon using YUM. This playbook targets all hosts, requires elevated privileges, and uses the 'yum' and 'service' modules. ```yaml --- - hosts: all become: yes tasks: - name: ensure ntpd is at the latest version yum: pkg=ntp state=latest notify: - restart ntpd handlers: - name: restart ntpd service: name=ntpd state=restarted ``` -------------------------------- ### List All Installed Plugins Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/plugin.mdx Displays a list of all globally installed Vagrant plugins and their versions. Version constraints used during installation are also shown. ```shell vagrant plugin list ``` -------------------------------- ### Download and Install VirtualBox Guest Additions via Command Line Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/virtualbox/boxes.mdx Automates the download, mounting, installation, and cleanup of VirtualBox Guest Additions using specific version 4.3.8 for command-line environments. ```shell wget http://download.virtualbox.org/virtualbox/4.3.8/VBoxGuestAdditions_4.3.8.iso sudo mkdir /media/VBoxGuestAdditions sudo mount -o loop,ro VBoxGuestAdditions_4.3.8.iso /media/VBoxGuestAdditions sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run rm VBoxGuestAdditions_4.3.8.iso sudo umount /media/VBoxGuestAdditions sudo rmdir /media/VBoxGuestAdditions ``` -------------------------------- ### Install a Plugin from a Local File Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/plugin.mdx Installs a plugin directly from a local .gem file. This is useful for development or when distributing plugins manually. ```shell vagrant plugin install /path/to/my-plugin.gem ``` -------------------------------- ### Box with Multiple Architectures Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/boxes/architecture.mdx This example shows how a single box can include providers for different architectures, such as amd64 and i386, for the same provider (e.g., virtualbox). ```text hashicorp/precise v1.0.0 provider: virtualbox, architecture: amd64 provider: virtualbox, architecture: i386 ``` -------------------------------- ### Install VirtualBox Guest Additions via GUI Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/virtualbox/boxes.mdx Executes the VirtualBox Guest Additions installation script from the mounted CD-ROM for Linux x86 systems. ```shell sudo sh /media/cdrom/VBoxLinuxAdditions.run ``` -------------------------------- ### Install Vagrant VMware Provider Plugin Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/installation.mdx Install the Vagrant VMware provider plugin using the standard Vagrant command. This is a required step after installing the Vagrant VMware Utility. ```shell $ vagrant plugin install vagrant-vmware-desktop ``` -------------------------------- ### Start HTTP Sharing Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/share/http.mdx Run `vagrant share` to start HTTP sharing. Vagrant will detect your HTTP server's port and provide a public URL. Press Ctrl-C to stop the session. ```shell $ vagrant share ==> default: Detecting network information for machine... default: Local machine address: 192.168.84.130 default: Local HTTP port: 9999 default: Local HTTPS port: disabled ==> default: Creating Vagrant Share session... ==> default: HTTP URL: http://b1fb1f3f.ngrok.io ``` -------------------------------- ### VMware Box Contents Example Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/boxes.mdx This example shows the typical file structure of a VMware base box, including disk images, configuration files, and metadata. ```shell $ tree . |-- disk-s001.vmdk |-- disk-s002.vmdk |-- ... |-- disk.vmdk |-- metadata.json |-- bionic64.nvram |-- bionic64.vmsd |-- bionic64.vmx |-- bionic64.vmxf 0 directories, 17 files ``` -------------------------------- ### Install a Plugin with a Specific Version Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/plugin.mdx Installs a specific version of a plugin, or a version that meets a defined constraint. Ensure version constraints are quoted on the command line. ```shell vagrant plugin install --plugin-version "> 1.0.2, < 1.1.0" my-plugin ``` -------------------------------- ### Install Vagrant Dependencies Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/installation/source.mdx Install the necessary Ruby gems for developing and building Vagrant using the bundle command. ```shell bundle install ``` -------------------------------- ### Example Direct Upload Response Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/api/v1.mdx This is an example JSON response when preparing for a direct upload. It contains the temporary upload path and the callback URL. ```json { "upload_path": "https://remote-storage.example.com/bucket/630e42d9-2364-2412-4121-18266770468e?auth=9023wqfda", "callback": "https://app.vagrantup.com/api/v1/box/myuser/test/version/1.2.3/provider/virtualbox/upload/direct/630e42d9-2364-2412-4121-18266770468e" } ``` -------------------------------- ### Initialize Vagrantfile for VMware Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/usage.mdx Create a new Vagrantfile to specify a VMware box. This is the initial setup for using the VMware provider. ```ruby # vagrant init hashicorp/bionic64 Vagrant.configure("2") do |config| config.vm.box = "hashicorp/bionic64" end ``` -------------------------------- ### Control Autostart Behavior for Machines Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/multi-machine.mdx Use the `autostart: false` option to prevent specific machines from starting automatically when `vagrant up` is executed. These machines can still be started manually. ```ruby config.vm.define "web"\nconfig.vm.define "db"\nconfig.vm.define "db_follower", autostart: false ``` -------------------------------- ### Start Vagrant VMware Utility Service on Linux (runit) Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/vagrant-vmware-utility.mdx Start the Vagrant VMware Utility service on Linux systems using runit. This is an alternative service management system. ```shell $ sudo sv start vagrant-vmware-utility ``` -------------------------------- ### Enable GUI Mode Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/virtualbox/configuration.mdx Set `v.gui = true` to start VirtualBox machines with a visible GUI. This is useful for debugging or observing machine behavior. ```ruby config.vm.provider "virtualbox" do |v| v.gui = true end ``` -------------------------------- ### Install Vagrant Share Plugin Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/share/index.mdx Install the Vagrant Share plugin using the Vagrant CLI. This plugin is required to use the sharing features. ```shell $ vagrant plugin install vagrant-share ``` -------------------------------- ### Run specific provisioners with Vagrant Source: https://context7.com/hashicorp/vagrant/llms.txt Execute specific provisioners for a Vagrant machine. Ensure the provisioners are installed and configured. ```shell vagrant provision --provision-with shell,ansible ``` -------------------------------- ### Manually Install Vagrant VMware Utility on Linux Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/vagrant-vmware-utility.mdx Use these commands to manually install the Vagrant VMware Utility on Linux systems when a system package is not available. This includes creating directories, unpacking the utility, and generating certificates. ```shell $ sudo mkdir -p /opt/vagrant-vmware-desktop/bin $ sudo unzip -d /opt/vagrant-vmware-desktop/bin vagrant-vmware-utility_1.0.0_linux_amd64.zip ``` ```shell $ sudo /opt/vagrant-vmware-desktop/bin/vagrant-vmware-utility certificate generate ``` ```shell $ sudo /opt/vagrant-vmware-desktop/bin/vagrant-vmware-utility service install ``` -------------------------------- ### Run Hook Before Provisioner Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/triggers/usage.mdx Use 'before' triggers to execute custom logic before a provisioner runs. This example shows a hook that runs before each provisioner. ```ruby config.trigger.before :provisioner_run, type: :hook do |t| t.info = "Before the provision!" end ``` ```ruby config.vm.provision "file", source: "scripts/script.sh", destination: "/test/script.sh" ``` ```ruby config.vm.provision "shell", inline: <<-SHELL echo "Provision the guest!" SHELL ``` -------------------------------- ### Get Host Port for SSH and Use in Script Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/port.mdx An example of using the `--guest` option to dynamically get the SSH port and use it in a command. ```shell $ ssh -p $(vagrant port --guest 22) ``` -------------------------------- ### Configure Dependency Provisioners in Vagrantfile Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/basic_usage.mdx This example demonstrates how to configure various dependency provisioners using `before` and `after` options, including the `:each` and `:all` shortcuts. Ensure these are used for advanced provisioning needs. ```ruby Vagrant.configure("2") do |config| config.vm.provision "C", after: "B", type: "shell", inline:<<-SHELL echo 'C' SHELL config.vm.provision "B", type: "shell", inline:<<-SHELL echo 'B' SHELL config.vm.provision "D", type: "shell", inline:<<-SHELL echo 'D' SHELL config.vm.provision "A", before: "B", type: "shell", inline:<<-SHELL echo 'A' SHELL config.vm.provision "Separate After", after: :each, type: "shell", inline:<<-SHELL echo '==============================' SHELL config.vm.provision "Separate Before", before: :each, type: "shell", inline:<<-SHELL echo '++++++++++++++++++++++++++++++' SHELL config.vm.provision "Hello", before: :all, type: "shell", inline:<<-SHELL echo 'HERE WE GO!!' SHELL config.vm.provision "Goodbye", after: :all, type: "shell", inline:<<-SHELL echo 'The end' SHELL end ``` -------------------------------- ### Initialize and Start a Vagrant Environment Source: https://github.com/hashicorp/vagrant/blob/main/README.md Use these commands to initialize a new Vagrant environment with a specified box and then bring it up. Vagrant automatically downloads the box if it's not already present. ```bash vagrant init hashicorp/bionic64 vagrant up ``` -------------------------------- ### Markdown List Item with Inline Code Example Source: https://github.com/hashicorp/vagrant/blob/main/website/README.md This markdown demonstrates a list item starting with inline code, which can break permalinks if changed. Avoid modifying such items or consult the digital marketing development team. ```markdown - this is a normal list item - `this` is a list item that begins with inline code ``` -------------------------------- ### Markdown List Item with Inline Code Example (Modified) Source: https://github.com/hashicorp/vagrant/blob/main/website/README.md This markdown shows a modified list item starting with inline code. Changes to headlines or list items beginning with inline code can break existing permalinks. ```markdown - lsdhfhksdjf - `this` jsdhfkdsjhkdsfjh ``` -------------------------------- ### Test Base Box with Vagrant Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/boxes/base.mdx Follow these commands to add your newly created box, initialize a Vagrant environment, and bring up the virtual machine to test its functionality. ```shell $ vagrant box add --name my-box /path/to/the/new.box ... $ vagrant init my-box ... $ vagrant up ... ``` -------------------------------- ### Upload Box Asset using Vagrant Cloud API v2 Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/api/v2.mdx Use this Ruby code to interact with the Vagrant Cloud API v2 to get an upload path and callback URL for a box asset. Ensure you have the 'http' gem installed and your VAGRANT_CLOUD_TOKEN environment variable set. ```ruby require "http" require "uri" api = HTTP.persistent("https://app.vagrantup.com").headers( "Authorization" => "Bearer #{ENV['VAGRANT_CLOUD_TOKEN']}" ) response = api.get("/api/v2/box/myuser/test/version/1.2.3/provider/virtualbox/amd64/upload") if response.status.success? # Success, you can now upload the box image to the returned URL upload_path = response.parse['upload_path'] callback = response.parse['callback'] # Upload the box asset HTTP.post upload_path, body: File.open("virtualbox-1.2.3.box") # Finalize the upload api.put(URI.parse(callback).path) else # Error, inspect the `errors` key for more information. p response.code, response.body end ``` -------------------------------- ### Install Ansible with Pip Args Only Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/ansible_local.mdx Use the 'pip_args_only' install mode to provide specific pip arguments for installing Ansible, such as referencing a requirements file. This mode assumes pip is already installed or will be handled separately. ```ruby config.vm.provision "ansible_local" do |ansible| ansible.playbook = "playbook.yml" ansible.install_mode = "pip_args_only" ansible.pip_args = "-r /vagrant/requirements.txt" end ``` -------------------------------- ### Install a Plugin from a Gem Source Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/plugin.mdx Installs a plugin from a remote gem source, such as RubyGems. If the plugin is already installed, it will be updated to the latest version. ```shell vagrant plugin install my-plugin ``` -------------------------------- ### Install VirtualBox Guest Additions Dependencies on Ubuntu Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/virtualbox/boxes.mdx Installs necessary kernel headers and development tools required before installing VirtualBox Guest Additions on Ubuntu systems. ```shell sudo apt-get install linux-headers-$(uname -r) build-essential dkms ``` -------------------------------- ### Start a VMware VM with Vagrant Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/usage.mdx Bring up a new VMware Fusion/Workstation virtual machine using the specified provider. The `--provider` flag is required. ```shell $ vagrant up --provider vmware_desktop ``` -------------------------------- ### Configure Shell Provisioning using Block Syntax Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/basic_usage.mdx This example demonstrates an alternative way to configure shell provisioning using a Ruby block, which can improve readability for multiple options. The `s.inline` attribute is used to specify the command. ```ruby Vagrant.configure("2") do |config| # ... other configuration config.vm.provision "shell" do |s| s.inline = "echo hello" end end ``` -------------------------------- ### Prepare and Upload Provider (Ruby) Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/api/v1.mdx This Ruby script demonstrates how to prepare for a direct provider upload, upload the asset, and finalize the process using the http gem. Ensure the VAGRANT_CLOUD_TOKEN environment variable is set. ```ruby # gem install http, or add `gem "http"` to your Gemfile require "http" require "uri" api = HTTP.persistent("https://app.vagrantup.com").headers( "Authorization" => "Bearer #{ENV['VAGRANT_CLOUD_TOKEN']}" ) response = api.get("/api/v1/box/myuser/test/version/1.2.3/provider/virtualbox/upload") if response.status.success? # Success, you can now upload the box image to the returned URL upload_path = response.parse['upload_path'] callback = response.parse['callback'] # Upload the box asset HTTP.post upload_path, body: File.open("virtualbox-1.2.3.box") # Finalize the upload api.put(URI.parse(callback).path) else # Error, inspect the `errors` key for more information. p response.code, response.body end ``` -------------------------------- ### Install Pip with Custom Command Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/ansible_local.mdx Override the default command used to install pip when using the 'pip' install_mode. This is helpful for environments with specific proxy configurations or custom installation procedures. ```ruby config.vm.provision "ansible_local" do |ansible| ansible.playbook = "playbook.yml" ansible.install_mode = "pip" ansible.pip_install_cmd = "https_proxy=http://your.proxy.server:port curl -s https://bootstrap.pypa.io/get-pip.py | sudo https_proxy=http/your.proxy.server:port python" ansible.version = "2.2.1.0" end ``` -------------------------------- ### Register Guest Capabilities in Go Plugin Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/plugins/go-plugins/guests.mdx Make a defined capability available to the plugin by implementing the `HasCapabilityFunc` and `CapabilityFunc` methods. This example registers the `write_hello` capability. ```go myplugin/guest/myguest.go // HasCapabilityFunc implements component.Guest func (h *AlwaysTrueGuest) HasCapabilityFunc() interface{} { return h.CheckCapability } func (h *AlwaysTrueGuest) CheckCapability(n *component.NamedCapability) bool { if n.Capability == "write_hello" { return true } return false } // CapabilityFunc implements component.Guest func (h *AlwaysTrueGuest) CapabilityFunc(name string) interface{} { if name == "write_hello" { return h.WriteHelloCap } return errors.New("Invalid capability requested") } func (h *AlwaysTrueGuest) WriteHelloCap(ui terminal.UI) error { return cap.WriteHello(ui) } ``` -------------------------------- ### Install Ansible Galaxy Roles with Root Permissions Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/ansible_local.mdx Use `ansible.galaxy_command` to prepend `sudo` when installing Ansible Galaxy roles to a system-owned path like `/etc/ansible/roles`. This ensures roles are correctly installed and accessible when using `become` in your playbooks. ```ruby Vagrant.configure(2) do |config| config.vm.box = "centos/7" config.vm.provision "ansible_local" do |ansible| ansible.become = true ansible.playbook = "playbook.yml" ansible.galaxy_role_file = "requirements.yml" ansible.galaxy_roles_path = "/etc/ansible/roles" ansible.galaxy_command = "sudo ansible-galaxy install --role-file=%{role_file} --roles-path=%{roles_path} --force" end end ``` -------------------------------- ### Trigger Output Example Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/triggers/usage.mdx This output demonstrates that the 'before :provisioner_run' hook executes prior to each provisioner, as shown by the 'Before the provision!' message appearing twice. ```shell ==> guest: Running provisioner: Sandbox (file)... ==> vagrant: Running hook triggers before provisioner_run ... ==> vagrant: Running trigger... ==> vagrant: Before the provision! guest: /home/hashicorp/vagrant-sandbox/scripts/script.sh => /home/vagrant/test/script.sh ==> guest: Running provisioner: shell... ==> vagrant: Running hook triggers before provisioner_run ... ==> vagrant: Running trigger... ==> vagrant: Before the provision! guest: Running: inline script guest: Provision the guest! ``` -------------------------------- ### Install Ansible with Pip and Custom Arguments Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/ansible_local.mdx Configure Ansible Local to install Ansible using pip and provide custom arguments, such as specifying an alternative package index URL. This allows for greater control over the pip installation process. ```ruby config.vm.provision "ansible_local" do |ansible| ansible.playbook = "playbook.yml" ansible.install_mode = :pip ansible.pip_args = "--index-url https://pypi.internal" end ``` -------------------------------- ### Configure VM as CFEngine Client Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/cfengine.mdx Configures the VM as a CFEngine client, bootstrapping it to a specified policy server address. Ensure the policy server is already running. ```ruby Vagrant.configure("2") do |config| config.vm.provision "cfengine" do |cf| cf.policy_server_address = "10.0.2.15" end end ``` -------------------------------- ### Basic Puppet Apply Provisioner Configuration Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/puppet_apply.mdx This is the most basic configuration to enable the Puppet provisioner. Ensure 'puppet' is installed on the guest VM. Vagrant defaults to looking for manifests in the 'manifests' folder and using 'default.pp' as the entry point. ```ruby Vagrant.configure("2") do |config| config.vm.provision "puppet" end ``` -------------------------------- ### List Installed Vagrant Boxes Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/basic_usage.mdx View all the boxes installed in your Vagrant environment. The provider for each box is shown in parentheses. ```shell $ vagrant box list bionic64 (virtualbox) bionic64 (vmware_fusion) ``` -------------------------------- ### Initialize with Box Name and URL Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/init.mdx Creates a Vagrantfile with a specific box name and its corresponding URL, allowing for custom box usage. ```shell $ vagrant init my-company-box https://example.com/my-company.box ``` -------------------------------- ### Example `info.json` Structure Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/boxes/info.mdx Include this JSON file within your base box to provide custom information displayed by `vagrant box list -i`. There are no predefined keys; use any relevant key-value pairs. ```json { "author": "brian", "homepage": "https://example.com" } ``` -------------------------------- ### Install a Plugin Locally Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cli/plugin.mdx Installs a plugin only for the current Vagrant project, rather than globally. This is useful for project-specific tools. ```shell vagrant plugin install --local my-plugin ``` -------------------------------- ### Example Upload Response Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/api/v1.mdx This is an example JSON response when requesting an upload URL for a provider. It contains the `upload_path` where the box image should be uploaded. ```json { "upload_path": "https://archivist.hashicorp.com/v1/object/630e42d9-2364-2412-4121-18266770468e" } ``` -------------------------------- ### Run Website Locally (Docker) Source: https://github.com/hashicorp/vagrant/blob/main/website/README.md After cloning the repository and ensuring Docker is installed, run these commands to build and serve the Vagrant website locally on http://localhost:3000. ```bash make http://localhost:3000 ``` -------------------------------- ### Basic Chef Zero Provisioner Configuration Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/chef_zero.mdx Configure the Chef Zero provisioner to specify local paths for Chef data and add recipes or roles. This example demonstrates setting cookbooks_path, data_bags_path, nodes_path, and roles_path, then adding an 'apache' recipe and a 'web' role. ```ruby Vagrant.configure("2") do |config| config.vm.provision "chef_zero" do |chef| # Specify the local paths where Chef data is stored chef.cookbooks_path = "cookbooks" chef.data_bags_path = "data_bags" chef.nodes_path = "nodes" chef.roles_path = "roles" # Add a recipe chef.add_recipe "apache" # Or maybe a role chef.add_role "web" end end ``` -------------------------------- ### Require Multiple Vagrant Plugins Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/vagrantfile/vagrant_settings.mdx Provide an array of plugin names to ensure multiple plugins are installed for the project. Vagrant will attempt to install any missing plugins. ```ruby config.vagrant.plugins = ["vagrant-plugin", "vagrant-other-plugin"] ``` -------------------------------- ### Basic Chef Solo Provisioning with a Recipe Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/chef_solo.mdx This snippet demonstrates the basic usage of the chef_solo provisioner to add a recipe to the run list. Cookbooks are expected in the default 'cookbooks' directory. ```ruby Vagrant.configure("2") do |config| config.vm.provision "chef_solo" do |chef| chef.add_recipe "apache" end end ``` -------------------------------- ### Initialize a New Vagrant Project with a Specific Box Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/boxes/using.mdx Use this command to initialize a new Vagrant project and specify the box to be used. This is useful when starting a new project from scratch. ```bash vagrant init hashicorp/bionic64 ``` -------------------------------- ### Require a Single Vagrant Plugin Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/vagrantfile/vagrant_settings.mdx Use a string to specify a single plugin that Vagrant should ensure is installed for the project. Vagrant will attempt to install it if it's missing. ```ruby config.vagrant.plugins = "vagrant-plugin" ``` -------------------------------- ### Box with Default Architecture (i386) Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/boxes/architecture.mdx This example shows how to change the default architecture to i386, ensuring that older Vagrant CLI versions will use the i386 provider when requesting the box. ```text hashicorp/precise v2.0.0 provider: virtualbox, architecture: amd64, default_architecture: false provider: virtualbox, architecture: i386, default_architecture: true ``` -------------------------------- ### List Installed Vagrant Boxes Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/boxes/versioning.mdx View a list of all Vagrant boxes currently installed on your system. This is useful for managing disk space and identifying boxes to prune. ```bash vagrant box list ``` -------------------------------- ### Vagrant Cloud JSON Error Response Example Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/api/v2.mdx This is an example of a JSON response that may include an 'errors' key with an array of error strings and a 'success' key. ```json { "errors": ["Resource not found!"] "success": false } ``` -------------------------------- ### Vagrant Plugin Entry Point Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/plugins/go-plugins/guests.mdx The main entry point for a Vagrant Go plugin. It uses `sdk.Main` to initialize the plugin with its components, such as the guest implementation defined in `guest/always_true_guest.go`. ```go // file: myplugin/main.go package myplugin import ( sdk "github.com/hashicorp/vagrant-plugin-sdk" "github.com/hashicorp/vagrant/builtin/myplugin/guest" ) // Options are the SDK options to use for instantiation. var ComponentOptions = []sdk.Option{ sdk.WithComponents( // Include the defined guest as a component defined in this plugin &guest.AlwaysTrueGuest{}, ), } func main() { sdk.Main(ComponentOptions...) os.Exit(0) } ``` -------------------------------- ### Vagrantfile Lookup Path Example Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/vagrantfile/index.mdx Vagrant searches for the Vagrantfile by climbing up the directory tree from the current directory. This example shows the order of directories Vagrant checks. ```bash ls /home/mitchellh/projects/foo/Vagrantfile ls /home/mitchellh/projects/Vagrantfile ls /home/mitchellh/Vagrantfile ls /home/Vagrantfile ls /Vagrantfile ``` -------------------------------- ### Configure Basic Synced Folder Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/synced-folders/basic_usage.mdx Use this to configure a basic synced folder. The first parameter is the host path, and the second is the absolute guest path. The guest path will be created if it doesn't exist. ```ruby Vagrant.configure("2") do |config| # other config here config.vm.synced_folder "src/", "/srv/website" end ``` -------------------------------- ### Output of `vagrant provision` with Dependency Provisioners Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/basic_usage.mdx This output shows the execution order of provisioners when using dependency configurations like `before`, `after`, `:each`, and `:all`. Observe how the scripts are run in the specified order. ```text ==> default: Running provisioner: Hello (shell)... default: Running: inline script default: HERE WE GO!! ==> default: Running provisioner: Separate Before (shell)... default: Running: inline script default: ++++++++++++++++++++++++++++++ ==> default: Running provisioner: A (shell)... default: Running: inline script default: A ==> default: Running provisioner: Separate After (shell)... default: Running: inline script default: ============================== ==> default: Running provisioner: Separate Before (shell)... default: Running: inline script default: ++++++++++++++++++++++++++++++ ==> default: Running provisioner: B (shell)... default: Running: inline script default: B ==> default: Running provisioner: Separate After (shell)... default: Running: inline script default: ============================== ==> default: Running provisioner: Separate Before (shell)... default: Running: inline script default: ++++++++++++++++++++++++++++++ ==> default: Running provisioner: C (shell)... default: Running: inline script default: C ==> default: Running provisioner: Separate After (shell)... default: Running: inline script default: ============================== ==> default: Running provisioner: Separate Before (shell)... default: Running: inline script default: ++++++++++++++++++++++++++++++ ==> default: Running provisioner: D (shell)... default: Running: inline script default: D ==> default: Running provisioner: Separate After (shell)... default: Running: inline script default: ============================== ==> default: Running provisioner: Goodbye (shell)... default: Running: inline script default: The end ``` -------------------------------- ### Start Vagrant VMware Utility Service on Windows Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/vagrant-vmware-utility.mdx Manually start the Vagrant VMware Utility service on Windows if it has stopped. This command requires administrator privileges. ```shell $ net.exe start vagrant-vmware-utility ``` -------------------------------- ### Host Machine Script Triggers Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/triggers/usage.mdx Define triggers to start and stop a service on the host machine using homebrew. Requires separate script files for starting and stopping. ```bash #/bin/bash # start-tinyproxy.sh brew services start tinyproxy ``` ```bash #/bin/bash # stop-tinyproxy.sh brew services stop tinyproxy ``` ```ruby Vagrant.configure("2") do |config| config.vm.define "ubuntu" do |ubuntu| ubuntu.vm.box = "ubuntu" ubuntu.trigger.before :up do |trigger| trigger.info = "Starting tinyproxy..." trigger.run = {path: "start-tinyproxy.sh"} end ubuntu.trigger.after :destroy, :halt do |trigger| trigger.info = "Stopping tinyproxy..." trigger.run = {path: "stop-tinyproxy.sh"} end end end ``` -------------------------------- ### Direct Upload a Provider (cURL) Source: https://github.com/hashicorp/vagrant/blob/main/website/content/vagrant-cloud/api/v2.mdx This cURL example shows a two-step direct upload process. First, it retrieves upload and callback URLs. Then, it uploads the box file to the `upload_path`. Finally, it calls the `callback` URL to finalize the upload. Both URLs are time-sensitive. ```shell response=$(curl \ --request GET \ --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \ https://app.vagrantup.com/api/v2/box/myuser/test/version/1.2.3/provider/virtualbox/amd64/upload/direct) # Requires the jq command upload_path=$(echo "$response" | jq .upload_path) callback=$(echo "$response" | jq .callback) curl \ --request PUT \ --upload-file virtualbox-1.2.3.box \ "${upload_path}" curl --request PUT \ --header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \ "${callback}" ``` -------------------------------- ### Execute Guest Script with Inline Provisioner Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/provisioning/shell.mdx Use an inline shell provisioner to execute a script that is already present on the guest machine. This is useful for invoking existing scripts without uploading them. ```ruby Vagrant.configure("2") do |config| config.vm.provision "shell", inline: "/bin/sh /path/to/the/script/already/on/the/guest.sh" end ``` -------------------------------- ### Vagrant VMware Utility Service Configuration Example Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/vagrant-vmware-utility.mdx An example HCL configuration file for the Vagrant VMware Utility service. This file allows customization of logging and API settings. ```hcl core { level = "info" } api { port = 9922 driver = "advanced" license_override = "standard" } ``` -------------------------------- ### Define Cloud-Init Config (Simplified Form) Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/cloud-init/usage.mdx Use the simplified hash form to define cloud-init configuration, specifying the content type and the path to a local script. ```ruby config.vm.cloud_init content_type: "text/x-shellscript", path: "./foo/bar.sh" ``` -------------------------------- ### Start Vagrant VMware Utility Service on Linux (SysVinit) Source: https://github.com/hashicorp/vagrant/blob/main/website/content/docs/providers/vmware/vagrant-vmware-utility.mdx Start the Vagrant VMware Utility service on Linux systems using SysVinit. This method is common on older Linux distributions. ```shell $ sudo /etc/init.d/vagrant-vmware-utility start ```