Skip to content

Instantly share code, notes, and snippets.

@EricTendian
Created May 30, 2017 02:37
Show Gist options
  • Save EricTendian/b41c25ac2c995137cdc61672708be02e to your computer and use it in GitHub Desktop.
Save EricTendian/b41c25ac2c995137cdc61672708be02e to your computer and use it in GitHub Desktop.
How to deploy a Vagrant Linux box in Microsoft Azure with a custom image
# NOTE: This was tested on a Blackboard Learn Vagrant machine in May 2017. Unknown how well the directions apply to other Vagrant machines.
# NOTE 2: Errors WILL occur as this is not well supported on Azure. You may need to do a fair bit of troubleshooting and pay close attention to these instructions.
# Step 1: Download the Vagrant .box file
wget BOX_FILE
# Step 2: Extract the .box file to the current directory (check the file format with the `file` command before you use tar)
tar xf BOX_FILE
# Step 3: Convert the resulting VMDK to a fixed size VHD
VBoxManage clonehd box-disk1.vmdk --format VHD --variant Fixed box-disk1.vhd
# Step 4: Upload the VHD to a storage account of your choice
az storage blob upload --account-name STORAGE_ACCOUNT_NAME --account-key STORAGE_ACCOUNT_KEY --container-name vhds --type page --file box-disk1.vhd --name AZURE_VHD_FILENAME
# Step 5: Create a new Virtual Machine using that custom VHD - this should hang, you should Ctrl+C it once the VM appears in the Portal with an IP address. VM creation should continue unharmed.
az vm create --resource-group RESOURCE_GROUP_NAME --location REGION --name VM_NAME --storage-account STORAGE_ACCOUNT_NAME --os-type linux --admin-username vagrant --ssh-key-value SSH_KEY_PATH --image URL_TO_VHD_FILE --size VM_SIZE --use-unmanaged-disk
# Step 6: Try to SSH in to the VM once it has an IP using the username/password combo from the Vagrant machine (vagrant/vagrant perhaps)
ssh vagrant@PUBLIC_IP
# Step 7 [ON VM]: Install the Azure agent (on Ubuntu in this example)
sudo apt-get install waagent
# Step 8 [ON VM]: Ensure the Azure agent daemon is enabled and started
sudo waagent -register-service
# Step 8 [ON VM]: Reboot the VM to ensure all the kernel changes are applied
sudo reboot
# Step 9: SSH in again to verify the machine has started up properly - you should get a warning that the remote host identification has changed, that is normal. Remove the old host key from ~/.ssh/known_hosts as prompted, then try the command again. If login succeeds, then exit the session and proceed to next step as provisioning should be complete.
ssh vagrant@PUBLIC_IP
# Step 10: Restart the VM in Azure to clear the failed provisioning state
az vm restart --resource-group RESOURCE_GROUP_NAME --name VM_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment