forked from codezoned/ScriptsDump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-cli-lab-environment.sh
More file actions
65 lines (58 loc) · 2.01 KB
/
azure-cli-lab-environment.sh
File metadata and controls
65 lines (58 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# This script, when run, creates X amounts of virtual machines in an azure subscription,
# with incrementing names (vm-1, vm-2, vm-3 etc)
# set all variables, log in to az-cli with 'az login' and run the script.
# The public IPs of the VMs are out printed out
# at the bottom of the prompt when the operation is complete
# Variables
vmcount="" # amount of VMs you want to create
resourcegroup="" # Resource Group
vmname="" # Name of Virtual Machine, becomes "name-1".."name-30", depends on the number in $vmcount
increment="+1" # Variable to increment Virtual Machine names (DO NOT CHANGE)
netsecgroup="" # Network Security Group
nsgrule="ssh" # Can be "ssh" or "rdp"
subnetname="" # Subnet Name
loc="" # Location (west europe, west us, etc.)
virtualnetwork="" # Virtual Network Name
admuser="" # Admin Username
sshkeyloc="" # Location of ssh key file
os="" # Operating System
vmsize="" # Virtual Machine specs
# Create resource requirements - operation fails if this does not exist
az group create -n $resourcegroup
az network vnet create -g $resourcegroup \
-n $virtualnetwork \
-l $loc \
--subnet-name $subnetname
# Loop to create the virtual machines
for run in {1..$vmcount}
do
az vm create -g $resourcegroup \
-n $vmname"-"$((increment++)) \
--nsg $netsecgroup \
--nsg-rule $nsgrule \
--subnet $subnetname \
-l $loc \
--vnet-name $virtualnetwork \
--admin-username $admuser \
--authentication-type ssh \
--ssh-key-value $sshkeyloc \
--image $os \
--size $vmsize \
#--no-wait
done
# spits out the public IP addresses in a neatly organized list
az network public-ip list -g $resourcegroup \
--out yaml \
| grep -e "name\|ipAddress" \
| grep -v "null\|Basic" \
| awk '{getline x;print x;}1'\
| awk '{print $2}' \
| sed 'N;s/\n/ /' \
# Example
# vmname-1PublicIP 23.11.158.166
# vmname-2PublicIP 13.22.45.146
# vmname-3PublicIP 13.33.3.28
# vmname-4PublicIP 13.44.182.227
# vmname-5PublicIP 13.55.179.164
# vmname-6PublicIP 13.66.176.226