### Ansible Playbook Example Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/provisioning/ansible_common A simple Ansible playbook to install and configure Nginx on the target machine. ```yaml --- - hosts: all become: yes tasks: - name: Update apt cache apt: update_cache=yes - name: Install Nginx apt: name=nginx state=present - name: Ensure Nginx is running service: name=nginx state=started enabled=yes ``` -------------------------------- ### Basic Shell Provisioner Source: https://developer.hashicorp.com/vagrant/docs/provisioning/basic_usage An example of a basic shell provisioner that runs an inline script. This is useful for simple setup tasks. ```shell ++++++++++++++++++++++++++++++ ``` -------------------------------- ### Directory Structure for Basic Puppet Provisioning Source: https://developer.hashicorp.com/vagrant/docs/provisioning/puppet_apply This example shows the minimal directory structure required for the basic Puppet provisioner setup. It includes the Vagrantfile and a default manifest file. ```bash $ tree . |-- Vagrantfile |-- manifests | |-- default.pp ``` -------------------------------- ### Configure Ubuntu Guest with Resized Primary Disk Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/disks/usage Example of configuring an Ubuntu guest with a primary disk resized to 100GB. This ensures the guest starts with the specified disk space. ```ruby Vagrant.configure("2") do |config| config.vm.define "hashicorp" do |h| h.vm.box = "hashicorp/bionic64" h.vm.provider :virtualbox h.vm.disk :disk, size: "100GB", primary: true end end ``` ```ruby Vagrant.configure("2") do |config| config.vm.define "hashicorp" do |h| h.vm.box = "hashicorp/bionic64" h.vm.provider :virtualbox h.vm.disk :disk, size: "100GB", primary: true end end ``` -------------------------------- ### Install VirtualBox Guest Additions (GUI Method) Source: https://developer.hashicorp.com/vagrant/docs/providers/virtualbox/boxes Execute the installation script for VirtualBox Guest Additions from the mounted CD-ROM on Linux x86 systems. ```bash $ sudo sh /media/cdrom/VBoxLinuxAdditions.run ``` -------------------------------- ### Download and Install VirtualBox Guest Additions (Command Line) Source: https://developer.hashicorp.com/vagrant/docs/providers/virtualbox/boxes Download, mount, and install VirtualBox Guest Additions using the command line. This method allows specifying the exact version. ```bash 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 ``` -------------------------------- ### Ansible Playbook to Install and Start NTP Source: https://developer.hashicorp.com/vagrant/docs/provisioning/ansible_intro A sample Ansible playbook that ensures the NTP daemon is installed and running. It uses the `yum` module for package management and `service` for managing the daemon's state. ```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 ``` -------------------------------- ### Example NFS Export Configuration Source: https://developer.hashicorp.com/vagrant/docs/synced-folders/nfs This is an example of the content that would be written to `/etc/exports` on the host when using specific `linux__nfs_options`. ```text # VAGRANT-BEGIN: 21171 5b8f0135-9e73-4166-9bfd-ac43d5f14261 "/path/to/vagrantfile" 172.28.128.5(rw,no_subtree_check,all_squash,async,anonuid=21171,anongid=660,fsid=3382034405) # VAGRANT-END: 21171 5b8f0135-9e73-4166-9bfd-ac43d5f14261 ``` -------------------------------- ### Install Ruby Dependencies Source: https://developer.hashicorp.com/vagrant/docs/installation/source Install the necessary Ruby gems and dependencies required to build Vagrant from source using the 'bundle install' command. ```bash bundle install ``` -------------------------------- ### Trigger Output Example Source: https://developer.hashicorp.com/vagrant/docs/triggers/usage This example shows the expected output when triggers are executed before provisioners, illustrating the order of operations and the trigger's informational message. ```text ==> 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 Linux Kernel Headers and Build Tools Source: https://developer.hashicorp.com/vagrant/docs/providers/virtualbox/boxes Install necessary packages on Ubuntu for building kernel modules, required before installing VirtualBox Guest Additions. ```bash $ sudo apt-get install linux-headers-$(uname -r) build-essential dkms ``` -------------------------------- ### Install Vagrant Share Plugin Source: https://developer.hashicorp.com/vagrant/docs/share Installs the Vagrant Share plugin. This command must be run to enable Vagrant Share functionality. ```bash $ vagrant plugin install vagrant-share ``` ```bash $ vagrant plugin install vagrant-share ``` -------------------------------- ### Execute Host Script to Start Tinyproxy Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/triggers/usage Define a trigger to execute a local host script using 'brew services start' to start the tinyproxy service. This script is run before the 'up' command. ```Bash #/bin/bash # start-tinyproxy.sh brew services start tinyproxy ``` -------------------------------- ### List Installed Plugins Source: https://developer.hashicorp.com/vagrant/docs/cli/plugin Lists all installed Vagrant plugins and their versions. Includes version constraints if specified during installation. ```bash vagrant plugin list ``` -------------------------------- ### Install Plugin from Local File Source: https://developer.hashicorp.com/vagrant/docs/cli/plugin Installs a plugin directly from a local .gem file. This is useful for development or when installing plugins not available in public repositories. ```bash vagrant plugin install /path/to/my-plugin.gem ``` -------------------------------- ### Manual Installation: Install Service Source: https://developer.hashicorp.com/vagrant/docs/providers/vmware/vagrant-vmware-utility Install and enable the Vagrant VMware Utility service on Linux after manual installation and certificate generation. This ensures the utility runs as a background service. ```bash $ sudo /opt/vagrant-vmware-desktop/bin/vagrant-vmware-utility service install ``` -------------------------------- ### Install Vagrant Plugin from Local File Source: https://developer.hashicorp.com/vagrant/docs/plugins/usage Use this command to install a Vagrant plugin from a local .gem file. Provide the correct path to the file. ```bash # Installing a plugin from a local file source $ vagrant plugin install /path/to/my-plugin.gem ``` -------------------------------- ### Install Multiple Plugins Source: https://developer.hashicorp.com/vagrant/docs/cli/plugin Installs multiple plugins by specifying their names or file paths. Flags applied will affect all plugins in the command invocation. ```bash vagrant plugin install plugin1 plugin2 ``` -------------------------------- ### Manual Installation: Create Directory and Unpack Utility Source: https://developer.hashicorp.com/vagrant/docs/providers/vmware/vagrant-vmware-utility Manually install the Vagrant VMware Utility on Linux by creating a directory and unpacking the zip package. This is a prerequisite for manual installation when no system package is available. ```bash $ 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 ``` -------------------------------- ### Install Plugin with Specific Version Source: https://developer.hashicorp.com/vagrant/docs/cli/plugin Installs a specific version of a plugin or a version range. Ensure to quote version constraints on the command line. ```bash vagrant plugin install --plugin-version "> 1.0.2, < 1.1.0" my-plugin ``` -------------------------------- ### Start Vagrant VMware Utility Service on Linux (runit) Source: https://developer.hashicorp.com/vagrant/docs/providers/vmware/vagrant-vmware-utility Start the Vagrant VMware Utility service on Linux systems using runit. Runit is a process supervision suite that can manage services. ```bash $ sudo sv start vagrant-vmware-utility ``` -------------------------------- ### Example Mount Command with Options Source: https://developer.hashicorp.com/vagrant/docs/synced-folders/nfs This shows the `mount` command executed on the guest when using the `mount_options` key for NFS synced folders. ```text mount -o 'actimeo=2' 172.28.128.1:'/path/to/vagrantfile' /vagrant ``` -------------------------------- ### Ruby Trigger Example Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/triggers/usage Define a Ruby trigger to execute custom Ruby code after the VM is brought up. This example uses Ruby to get guest ostype information. ```ruby Vagrant.configure("2") do |config| config.vm.define "ubuntu" do |ubuntu| ubuntu.vm.box = "ubuntu" ubuntu.trigger.after :up do |trigger| trigger.info = "More information with ruby magic" trigger.ruby do |env,machine| puts `VBoxManage showvminfo #{machine.id} --machinereadable | grep ostype` end end end end ``` ```ruby Vagrant.configure("2") do |config| config.vm.define "ubuntu" do |ubuntu| ubuntu.vm.box = "ubuntu" ubuntu.trigger.after :up do |trigger| trigger.info = "More information with ruby magic" trigger.ruby do |env,machine| puts `VBoxManage showvminfo #{machine.id} --machinereadable | grep ostype` end end end end ``` -------------------------------- ### Shell Provisioner with Block Syntax Source: https://developer.hashicorp.com/vagrant/docs/provisioning/basic_usage This example demonstrates an alternative block-based syntax for configuring a shell provisioner. This syntax can improve readability for provisioners with multiple options and allows for more complex configurations. ```ruby Vagrant.configure("2") do |config| # ... other configuration config.vm.provision "shell" do |s| s.inline = "echo hello" end end ``` -------------------------------- ### Multi-Machine Docker Vagrantfile Configuration Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/providers/docker/commands Example Vagrantfile for a multi-machine setup using the Docker provider, defining 'web' and 'consul' VMs. ```ruby Vagrant.configure do |config| config.vm.define "web" do config.vm.provider "docker" do |d| d.image = "nginx" end end config.vm.define "consul" do config.vm.provider "docker" do |d| d.image = "consul" end end end ``` ```ruby Vagrant.configure do |config| config.vm.define "web" do config.vm.provider "docker" do |d| d.image = "nginx" end end config.vm.define "consul" do config.vm.provider "docker" do |d| d.image = "consul" end end end ``` -------------------------------- ### Vagrantfile Configuration for Tinyproxy Triggers Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/triggers/usage Configure Vagrant triggers in the Vagrantfile to start tinyproxy before 'up' and stop it after 'destroy' or 'halt'. This example uses local host scripts. ```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 ``` -------------------------------- ### Create a Base Vagrantfile Source: https://developer.hashicorp.com/vagrant/docs/cli/init Initializes a new Vagrant environment with a specified base box. This is the most common usage for starting a new project. ```bash $ vagrant init hashicorp/bionic64 ``` ```bash $ vagrant init hashicorp/bionic64 ``` -------------------------------- ### Example Box Catalog Metadata JSON Source: https://developer.hashicorp.com/vagrant/docs/boxes/box_repository This JSON structure defines a Vagrant box, including its name, description, versions, and providers. It is used by Vagrant to manage box installations and updates. ```json { "name": "hashicorp/bionic64", "description": "This box contains Ubuntu 18.04 LTS 64-bit.", "versions": [ { "version": "0.1.0", "providers": [ { "name": "virtualbox", "url": "http://example.com/bionic64_010_virtualbox.box", "checksum_type": "sha1", "checksum": "foo", "architecture": "amd64", "default_architecture": true } ] } ] } ``` -------------------------------- ### Ansible Parallel Execution from a Guest Controller Source: https://developer.hashicorp.com/vagrant/docs/provisioning/ansible_local Configure a dedicated 'controller' machine to install and execute Ansible, provisioning other machines in the Vagrant environment. This setup requires defining multiple machines and specifying Ansible provisioning on the controller. ```ruby Vagrant.configure("2") do |configf| config.vm.box = "ubuntu/trusty64" config.vm.define "node1" do |machine| machine.vm.network "private_network", ip: "172.17.177.21" end config.vm.define "node2" do |machine| machine.vm.network "private_network", ip: "172.17.177.22" end config.vm.define 'controller' do |machine| machine.vm.network "private_network", ip: "172.17.177.11" machine.vm.provision :ansible_local do |ansible| ansible.playbook = "example.yml" ansible.verbose = true ansible.install = true ansible.limit = "all" # or only "nodes" group, etc. ansible.inventory_path = "inventory" end end end ``` -------------------------------- ### Example Output of Vagrant Provisioning Execution Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/provisioning/basic_usage This output illustrates the order in which Vagrant executes provisioners, including dependency provisioners, when 'vagrant provision' is run. It shows the output of inline shell scripts for each provisioner. ```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 ``` -------------------------------- ### Configure VM as CFEngine Client Source: https://developer.hashicorp.com/vagrant/docs/provisioning/cfengine Installs and bootstraps a CFEngine client on the VM, connecting it to a specified policy server address. ```ruby Vagrant.configure("2") do |config| config.vm.provision "cfengine" do |cf| cf.policy_server_address = "10.0.2.15" end end ``` -------------------------------- ### Basic Rakefile for Vagrant Plugin Packaging Source: https://developer.hashicorp.com/vagrant/docs/plugins/packaging This Rakefile includes the necessary setup for Bundler and installs the default Rake tasks provided by `Bundler::GemHelper`. These tasks typically include `package` and `release` for building and distributing the plugin gem. ```ruby require "rubygems" require "bundler/setup" Bundler::GemHelper.install_tasks ``` ```ruby require "rubygems" require "bundler/setup" Bundler::GemHelper.install_tasks ``` -------------------------------- ### Hook Trigger Execution Log Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/triggers/usage Example log output demonstrating a hook trigger running before provisioners. ```text ==> 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! ``` ```text ==> 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! ``` -------------------------------- ### Initialize Vagrant Project with Local Executable Source: https://developer.hashicorp.com/vagrant/docs/installation/source Initialize a new Vagrant project using the locally generated Vagrant executable, specifying the desired base box. ```bash /path/to/vagrant/exec/vagrant init -m hashicorp/bionic64 ``` -------------------------------- ### Install Plugin from Gem Source Source: https://developer.hashicorp.com/vagrant/docs/cli/plugin Installs a plugin from a remote repository, typically RubyGems. This is the standard way to install publicly available plugins. ```bash vagrant plugin install my-plugin ``` -------------------------------- ### Basic Puppet Apply Provisioner Configuration Source: https://developer.hashicorp.com/vagrant/docs/provisioning/puppet_apply This is the most basic configuration to enable the Puppet provisioner. It assumes Puppet is installed on the guest and defaults to using manifests found in the 'manifests' directory with 'default.pp' as the entry point. ```ruby Vagrant.configure("2") do |config| config.vm.provision "puppet" end ``` -------------------------------- ### Configure VM as CFEngine Policy Server Source: https://developer.hashicorp.com/vagrant/docs/provisioning/cfengine Sets up the current VM to act as a CFEngine policy hub. The host is automatically bootstrapped to itself. ```ruby Vagrant.configure("2") do |config| config.vm.provision "cfengine" do |cf| cf.am_policy_hub = true end end ``` -------------------------------- ### Update Installed Boxes Source: https://developer.hashicorp.com/vagrant/docs/boxes/versioning Download and install the latest available versions of your installed Vagrant boxes. Note that this does not update running Vagrant environments; they require recreation. ```bash vagrant box update ``` -------------------------------- ### Attach Optical Drive with ISO Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/disks/usage Configure a guest to attach an ISO file as an optical drive. This is useful for mounting installation media. Ensure the file path is correct. ```ruby Vagrant.configure("2") do |config| config.vm.define "hashicorp" do |h| h.vm.box = "hashicorp/bionic64" h.vm.provider :virtualbox h.vm.disk :dvd, name: "installer", file: "./installer.iso" end end ``` ```ruby Vagrant.configure("2") do |config| config.vm.define "hashicorp" do |h| h.vm.box = "hashicorp/bionic64" h.vm.provider :virtualbox h.vm.disk :dvd, name: "installer", file: "./installer.iso" end end ``` -------------------------------- ### List Installed Boxes Source: https://developer.hashicorp.com/vagrant/docs/boxes/versioning View all installed versions of Vagrant boxes on your system. ```bash vagrant box list ``` -------------------------------- ### Initialize a new Vagrant environment with a specific box Source: https://developer.hashicorp.com/vagrant/docs/boxes Use the `vagrant init` command to create a new Vagrantfile and initialize your environment with the specified box. This is useful for starting a new project from scratch. ```bash $ vagrant init hashicorp/bionic64 ``` ```bash $ vagrant init hashicorp/bionic64 ``` -------------------------------- ### Install Ansible Galaxy Roles with Sudo Source: https://developer.hashicorp.com/vagrant/docs/provisioning/ansible_local Use `ansible.galaxy_command` to prepend `sudo` to the `ansible-galaxy` command when installing roles to a root-owned path. This ensures roles are correctly installed and found by playbooks using `become`. ```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 ``` -------------------------------- ### Basic Chef Solo Provisioning with a Recipe Source: https://developer.hashicorp.com/vagrant/docs/provisioning/chef_solo This snippet shows the basic configuration for the Chef Solo provisioner, adding a single 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 Vagrant with VMware Box Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/providers/vmware/usage Use this command to create a new Vagrantfile configured for a VMware box. This sets up the basic configuration for your virtual machine. ```bash # vagrant init hashicorp/bionic64 Vagrant.configure("2") do |config| config.vm.box = "hashicorp/bionic64" end ``` -------------------------------- ### Guest Directory Structure After Upload Source: https://developer.hashicorp.com/vagrant/docs/provisioning/file Example of the directory structure on the guest machine after the 'file' provisioner has copied the host directory. ```text newfolder ├── script.sh ├── otherfolder │   └── hello.sh ├── goodbye.sh ├── hello.sh └── woot.sh 1 directory, 5 files ``` -------------------------------- ### Basic Before Trigger Example Source: https://developer.hashicorp.com/vagrant/docs/triggers/configuration A simple example of a 'before' operation trigger that displays an informational message. ```ruby config.trigger.before :up do |t| t.info = "Bringing up your Vagrant guest machine!" end ``` -------------------------------- ### Default Pip Installation Command Source: https://developer.hashicorp.com/vagrant/docs/provisioning/ansible_local This command is used by Vagrant to install pip if it's not already present. ```bash curl https://bootstrap.pypa.io/get-pip.py | sudo python ``` -------------------------------- ### Install Plugin Locally Source: https://developer.hashicorp.com/vagrant/docs/cli/plugin Installs a plugin only for the current Vagrant project, not globally. This is useful for project-specific customizations. ```bash vagrant plugin install --local my-plugin ``` -------------------------------- ### Ansible Raw Arguments Example Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/provisioning/ansible_common Provides a list of additional arguments to pass to the `ansible-playbook` command. Use with caution as these can override Vagrant settings. ```ruby ['--check', '-M', '/my/modules'] ``` ```ruby ["--connection=paramiko", "--forks=10"] ``` -------------------------------- ### Box metadata.json Example Source: https://developer.hashicorp.com/vagrant/docs/boxes/format Shows the required structure for metadata.json, specifying the target provider for the box. ```json { "provider": "virtualbox" } ``` -------------------------------- ### Custom Pip Installation Command Source: https://developer.hashicorp.com/vagrant/docs/provisioning/ansible_local This command is executed to install pip when a custom command is provided via `pip_install_cmd`. ```bash https_proxy=http://your.proxy.server:port curl -s https://bootstrap.pypa.io/get-pip.py | sudo https_proxy=http://your.proxy.server:porpython ``` -------------------------------- ### Output of Vagrant Provisioning with Dependency Provisioners Source: https://developer.hashicorp.com/vagrant/docs/provisioning/basic_usage This output shows the execution order of provisioners when dependency provisioners are configured. It illustrates how 'before' and 'after' options affect the provisioning sequence. ```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 ``` ```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 ``` -------------------------------- ### Pip Install Command for Ansible Source: https://developer.hashicorp.com/vagrant/docs/provisioning/ansible_local This command is executed by Vagrant to install a specific Ansible version using pip. ```bash sudo pip install --upgrade ansible==2.2.1.0 ``` -------------------------------- ### Configure cloud-init with Path Source: https://developer.hashicorp.com/vagrant/docs/cloud-init/configuration Use this to specify a file path for cloud-init user data. Ensure the content_type is correctly set. ```ruby config.vm.cloud_init :user_data, content_type: "text/cloud-config", path: "config.cfg" ``` -------------------------------- ### Install Vagrant VMware Plugin Source: https://developer.hashicorp.com/vagrant/docs/providers/vmware/faq Re-run the install command to update the Vagrant VMware plugin to the latest version. ```bash $ vagrant plugin install vagrant-vmware-desktop ``` -------------------------------- ### Provisioner Execution Order in Multi-Machine Source: https://developer.hashicorp.com/vagrant/docs/multi-machine Demonstrates the execution order of provisioners in a multi-machine setup. Provisioners outside the `config.vm.define` block execute before those inside, following the order they appear in the Vagrantfile. ```ruby Vagrant.configure("2") do |config| config.vm.provision :shell, inline: "echo A" config.vm.define :testing do |test| test.vm.provision :shell, inline: "echo B" end config.vm.provision :shell, inline: "echo C" end ``` -------------------------------- ### Command Trigger Example Source: https://developer.hashicorp.com/vagrant/docs/triggers/configuration An example of an 'after' trigger configured to run after a 'destroy' command, displaying a warning message. ```ruby config.trigger.after :destroy, type: :command do |t| t.warn = "Destroy command completed" end ``` -------------------------------- ### Basic Shell Provisioner with Inline Command Source: https://developer.hashicorp.com/vagrant/docs/provisioning/basic_usage This snippet shows the most basic way to configure a shell provisioner to run a simple inline command. It uses the standard `config.vm.provision` method with the type and the inline command. ```ruby Vagrant.configure("2") do |config| # ... other configuration config.vm.provision "shell", inline: "echo hello" end ``` -------------------------------- ### Require a Single Vagrant Plugin Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/vagrantfile/vagrant_settings Specify a single plugin to be installed for the local project. Vagrant will attempt to install it if not present. ```ruby config.vagrant.plugins = "vagrant-plugin" ``` -------------------------------- ### Hook Trigger Example Source: https://developer.hashicorp.com/vagrant/docs/v2.4.8/triggers/usage Define a hook-type trigger to execute before or after specific Vagrant internal events. This example runs before each provisioner. ```ruby config.trigger.before :provisioner_run, type: :hook do |t| t.info = "Before the provision!" end config.vm.provision "file", source: "scripts/script.sh", destination: "/test/script.sh" config.vm.provision "shell", inline: <<-SHELL echo "Provision the guest!" SHELL ``` ```ruby config.trigger.before :provisioner_run, type: :hook do |t| t.info = "Before the provision!" end config.vm.provision "file", source: "scripts/script.sh", destination: "/test/script.sh" config.vm.provision "shell", inline: <<-SHELL echo "Provision the guest!" SHELL ```