Azure CLI#

The Azure command-line interface (az) is the operator’s environment for creating and managing Azure resources from the terminal.

Login#

$ az login -u myemail@address.com
$ az account list                              # list accounts
$ az account set --subscription "xxx"          # set subscription
$ az account list-locations                    # list locations
$ az resource list                             # list resource groups
$ azure --version                              # CLI version
$ azure help                                   # help

VMs#

$ az vm list-sizes --location <region>                              # available sizes
$ az vm image list --output table                                   # available images
$ az vm create --resource-group myResourceGroup --name myVM --image ubunlts
$ 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

VM extensions#

$ 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

Batch#

$ 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
$ az batch account login -g myresourcegroup -n mybatchaccount
$ az batch account show -g myresourcegroup -n mybatchaccount

# applications
$ 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

# pools
$ 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

# nodes
$ az batch node list --pool-id mypool-linux
$ 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

# jobs and tasks
$ az batch job create --id myjob --pool-id mypool
$ 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
$ 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

Containers#

# with SSH (about 10 minutes)
$ az acs create -n acs-cluster -g acsrg1 -d applink789

# without SSH (about 10 minutes)
$ 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

References#