Azure CLI 2.0 cheatsheet for Login, Resources, VMs, Resource groups, Storage, Batch, and Containers.
az login
az login -u [email protected]
az account list
az account set --subscription "xxx"
az account list-locations
az resource list
azure --version
azure help
az vm list-sizes --location eastus
az vm image list --output table
az vm create --resource-group myResourceGroup --name myVM --image ubuntults
az vm create --resource-group myResourceGroup --name myVM --image win2016datacenter
az group create --name myresourcegroup --location eastus
az storage account create -g myresourcegroup -n mystorageaccount -l eastus --sku Standard_LRS
az group delete --name myResourceGroup
az vm list
az vm start --resource-group myResourceGroup --name myVM
az vm stop --resource-group myResourceGroup --name myVM
az vm deallocate --resource-group myResourceGroup --name myVM
az vm restart --resource-group myResourceGroup --name myVM
az vm redeploy --resource-group myResourceGroup --name myVM
az vm delete --resource-group myResourceGroup --name myVM
az image create --resource-group myResourceGroup --source myVM --name myImage
az vm create --resource-group myResourceGroup --name myNewVM --image myImage
az vm extension list --resource-group azure-playground-resources --vm-name azure-playground-vm
az vm extension delete --resource-group azure-playground-resources --vm-name azure-playground-vm --name bootstrapper
az batch account create -g myresourcegroup -n mybatchaccount -l eastus
az storage account create -g myresourcegroup -n mystorageaccount -l eastus --sku Standard_LRS
az batch account set -g myresourcegroup -n mybatchaccount --storage-account mystorageaccount
We can now authenticate directly against the account for further CLI interaction.
az batch account login -g myresourcegroup -n mybatchaccount
az batch account show -g myresourcegroup -n mybatchaccount
az batch application create --resource-group myresourcegroup --name mybatchaccount --application-id myapp --display-name "My Application"
az batch application package create --resource-group myresourcegroup --name mybatchaccount --application-id myapp --package-file my-application-exe.zip --version 1.0
az batch application set --resource-group myresourcegroup --name mybatchaccount --application-id myapp --default-version 1.0
az batch pool node-agent-skus list
az batch pool create \
--id mypool-linux \
--vm-size Standard_A1 \
--image canonical:ubuntuserver:16.04.0-LTS \
--node-agent-sku-id “batch.node.ubuntu 16.04”
az batch pool resize --pool-id mypool-linux --target-dedicated 5
az batch pool show --pool-id mypool-linux
az batch node list --pool-id mypool-linux
If a particular node in the pool is having issues, it can be rebooted or reimaged. A typical node ID will be in the format 'tvm-xxxxxxxxxx_1-'.
az batch node reboot --pool-id mypool-linux --node-id tvm-123_1-20170316t000000z
az batch node delete \
--pool-id mypool-linux \
--node-list tvm-123_1-20170316t000000z tvm-123_2-20170316t000000z \
--node-deallocation-option requeue
az batch job create --id myjob --pool-id mypool
…where is your preferred shell for execution (/bin/sh, /bin/bash, /bin/ksh etc.), and /path/to/script.sh is, of course, the full path of the shell script you’re invoking to get things started.
az batch task create --job-id myjob --task-id task1 --application-package-references myapp#1.0 --command-line "/bin/<shell> -c /path/to/script.sh"
az batch task create --job-id myjob --json-file tasks.json
Now that all the tasks are added - we can update the job so that it will automatically be marked as completed once all the tasks are finished.
az batch job set --job-id myjob --on-all-tasks-complete terminateJob
az batch job show --job-id myjob
az batch task show --job-id myjob --task-id task1
az batch job delete --job-id myjob
If you HAVE AN SSH run this to create an Azure Container Service Cluster (~10 mins)
az acs create -n acs-cluster -g acsrg1 -d applink789
If you DO NOT HAVE AN SSH run this to create an Azure Container Service Cluster (~10 mins)
az acs create -n acs-cluster -g acsrg1 -d applink789 --generate-ssh-keys
az acs list --output table
az acs list -g acsrg1 --output table
az acs show -g acsrg1 -n acs-cluster --output list
az acs scale -g acsrg1 -n acs-cluster --new-agent-count 4
az acs delete -g acsrg1 -n acs-cluster