Last active
May 8, 2018 10:43
-
-
Save marinnedea/5d470880e9cca844cad21ba456784ace to your computer and use it in GitHub Desktop.
Interactiv Deployment Linux VM script that, post deployment, will run a custom script from your local Linux box on the newly deployed VM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script is provided as it is and | |
# there's no guarantee that this will | |
# work for you. | |
# Please adapt it to your needs! | |
# Get the variables | |
read -p 'Resource Group: ' my_resource_group | |
read -p 'VM Name:' vmname | |
read -p 'Linux VM Image: ' linux_image | |
read -p 'Azure VM size: ' vmsize | |
read -p 'VNET Name: ' vnetname | |
read -p 'Subnet Name: ' subnetname | |
read -p 'Public IP Address Name: ' pipname | |
read -p 'Public IP Address Allocation (1 for dynamic/ 2 for static): ' pipallocation | |
read -p 'NSG Name: ' nsgname | |
read -p 'Azure Region: ' locationname | |
read -p 'Admin Username: ' adminusername | |
read -p 'SSH key value: ' sshkeyval | |
read -p 'Custom Script path on your local box: ' scriptpath | |
# convert the pipaloation value to static/dynamic | |
[ $pipallocation == 1 ] && pipallocationvalue="dynamic" || pipallocationvalue="static" | |
# Check if the path to the script is correct. | |
# The correct path should be like /path/to/script.sh | |
finished=false | |
while ! finished ; do | |
[ ! -f $scriptpath ] && echo "There is no file in location $scriptpath. Try again!" ; read -p 'Custom Script path on your local box: ' scriptpath || echo "Your script location is: $scriptpath " | |
finished=true | |
done | |
# create the VM | |
az vm create -g $my_resource_group -n $vmname --image $linux_image --vnet-name $vnetname --subnet $subnetname --nsg $nsgname -l $locationname --admin-username $adminusername --public-ip-address $pipname --public-ip-address-allocation $pipallocationvalue --size $vmsize --ssh-key-value $sshkeyval | |
# run the script on the newly deployed VM | |
az vm run command-invoke -g $my_resource_group -n $vmname --command-id RunShellScript --script @$scriptpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment