Creating a Vagrantfile

Each Vagrant environment is defined using a configuration file called Vagrantfile (with no file extension). Instead of specifying source images with a boxfile, Skytap Vagrantfiles use a vm_url setting that references an existing VM in a Skytap Cloud environment or template.

Contents

Generate a Vagrantfile from an existing Skytap Cloud environment or template

To create a Vagrantfile from an existing Skytap Cloud environment or template
  1. Navigate to an environment or template in your Skytap Cloud account.
  2. In the address bar of the internet browser, edit the URL to replace everything after the environment or template ID with /vagrantfile .
    • Environment - For example, https://cloud.skytap.com/configurations/112233?sort=svms&thumbnails=shown&env_details_meta_info=1&ga=1 would become https://cloud.skytap.com/configurations/112233/vagrantfile.
    • Template - For example, /vagrantfile would become https://cloud.skytap.com/templates/112233/vagrantfile
  3. Enter your Skytap Cloud username and API token in the skytap.username and skytap.api_token variables. If you don’t want to store your username and API token in the Vagrantfile, set them as environment variables (VAGRANT_SKYTAP_USERNAME and VAGRANT_SKYTAP_API_TOKEN).

Tips

  • To automatically include your user credentials in the generated Vagrantfile, include
    ?include_api_credentials=true in the URL.

    Don’t use this option if you intend to share the Vagrantfile with other users.

  • To automatically include the VM hardware properties in the generated Vagrantfile, include
    ?include_hardware_properties=true in the URL.

Manually create a Vagrantfile

To create a Vagrantfile for use with Skytap Cloud VMs
  1. Create an empty file called Vagrantfile. The file should not have a file extension in the name (it should be Vagrantfile, not Vagrantfile.txt).
  2. Copy the following text into the file. With some slight modification, this Vagrantfile creates a Skytap Cloud environment in the US-West region that contains two Ubuntu servers from the public template library. The VMs are identical except for their hardware settings.

     Vagrant.configure(2) do |config|
         # This box file only exists to satisfy Vagrant’s requirements.
         # Specify the base image for each machine using the vm_url
         # setting below.
         config.vm.box = "skytap/empty"
    
         config.vm.provider :skytap do |skytap, override|
             # Replace these settings with your own Skytap username
             # and API token.
             skytap.username = "jsmith"
             skytap.api_token = "0c12620172e0dd1c8279e25d19d8120510c7e166"
         end
    
         # Define a machine named "web" with 2 CPUs and 1GB of RAM.
         config.vm.define "web" do |server|
             server.vm.provider :skytap do |box|
                 box.vm_url = "https://cloud.skytap.com/vms/3157858"
                 box.cpus = 2
                 box.cpuspersocket = 1
                 box.ram = 1024
                 # box.vpn_url = "https://cloud.skytap.com/vpns/999999"
             end
             # Configure an NFS share. The contents of /local/directory
             # will be visible on the VM as /synced.
             # server.vm.synced_folder "/local/directory", "/synced", type: :nfs
             # Configure port forwarding.
             # server.vm.network "forwarded_port", guest: 80, host: 8080,
             #   auto_correct: true
         end
    
         # Define a machine named "db" with 2 quad-core CPUs and
         # 8GB of RAM.
         config.vm.define "db" do |server|
             server.vm.provider :skytap do |box|
                 box.vm_url = "https://cloud.skytap.com/vms/3157858"
                 box.cpus = 8
                 box.cpuspersocket = 4
                 box.ram = 8192
             end
         end
     end
    
  3. Enter your Skytap username and API token in the skytap.username and skytap.api_token variables. If you don’t want to store your username and API token in the Vagrantfile, set them as environment variables (VAGRANT_SKYTAP_USERNAME and VAGRANT_SKYTAP_API_TOKEN).
  4. Optionally, you can further customize the Vagrantfile (see below).

Customizing a Vagrantfile

Add a VM

Before you add a Skytap VM to a Vagrantfile, confirm the VM is:
To add a VM to the Vagrant
  1. Create a VM definition section in the Vagrantfile. The VM definition must include the following:
     # Define a machine named "vnname"
     config.vm.define "vmname" do |server|
         server.vm.provider :skytap do |box|
             box.vm_url = "https://cloud.skytap.com/vms/3157858"
         end
     end
    

    Replace the ID number in the box.vm_url with the VM ID from a VM in a Skytap Cloud template. For help finding the ID number, see Finding the ID for a VM, Environment, or Template.

  2. For Windows VMs: Follow Vagrant’s instructions for adding WinRM settings to the Vagrantfile. You must store the Windows RM credentials in the Vagrantfile. If credentials are not provided, the default “vagrant/vagrant” is used.

Edit the VM hardware settings

Edit or omit the box.cpus, box.cpuspersocket, and/or box.ram variables in the VM definition section of the Vagrantfile. These settings override the Skytap Cloud hardware settings for the VM.

# Define a machine named "web" with 2 CPUs and 1GB of RAM.
config.vm.define "web" do |server|
    server.vm.provider :skytap do |box|
        box.vm_url = "https://cloud.skytap.com/vms/3157858"
        box.cpus = 2
        box.cpuspersocket = 1
        box.ram = 1024
    end
end

Enable NFS synced folders

Include a vm.synced_folder path in the VM definition section.

In the following example, a local directory /local/directory is visible on the VM at the path /synced.

# Define a machine named "web" with 2 CPUs and 1GB of RAM.
    config.vm.define "web" do |server|
        server.vm.provider :skytap do |box|
            box.vm_url = "https://cloud.skytap.com/vms/3157858"
        end
        server.vm.synced_folder "/local/directory", "/synced", type: :nfs
    end

For more information, see the Vagrant documentation: https://docs.vagrantup.com/v2/synced-folders/index.html.

Enable port forwarding

The Skytap Vagrant provider supports Vagrant’s port forwarding feature using AutoSSH, an open-source utility for managing SSH tunnels.

To add port forwarding, include a vm.network line in the VM definition section of the Vagrantfile.

In the following example, port 8080 on the Vagrant host machine is forwarded to port 80 on the VM created by Vagrant. The auto-correct setting is used.

# Define a machine named "web" with 2 CPUs and 1GB of RAM.
config.vm.define "web" do |server|
    server.vm.provider :skytap do |box|
        box.vm_url = "https://cloud.skytap.com/vms/3157858"
    end
    server.vm.network "forwarded_port", guest: 80, host: 8080,
        auto_correct: true
end

When port forwarding is defined, the Vagrant up and resume commands start a separate AutoSSH process for each forwarded port. The halt and suspend commands terminate the AutoSSH processes, which causes the SSH tunnels to be killed. vagrant reload kills the AutoSSH processes and recreates them (Only AutoSSH processes created by Vagrant is killed, and only for the VMs being halted, suspended, or reloaded).

For more information, see the Vagrant documentation: https://www.vagrantup.com/docs/networking/forwarded_ports.html.

Notes

  • AutoSSH must be installed on the local machine.
  • Port forwarding is supported only for TCP.
  • Port forwarding is not supported on Windows hosts.

Skytap-specific Vagrantfile settings

Setting Required? Description
vm_url Required The URL of the source VM to use when creating a new VM
cpus Optional The number of CPU virtual cores
cpuspersocket Optional The number of virtual cores per CPU
ram Optional RAM (in MB)
guestos Optional The VMware guest OS for the VM
vpn_url Optional The URL of the Skytap Cloud VPN to use when connecting to the VM

For a complete list of Vagrant commands supported in Skytap Cloud, see Supported Vagrant commands.