az vmss update for updating the DNS - azure

I have a VMSS on Azure and I need to change the DNS server of it. I have found the Azure CLI command for this but I can't figure it out how the final form of it.
This is what I have:
az vmss update -n myVmss --set virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].dnsSettings
What am I doing wrong?

az vmss update -n myVmss --set virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].dnsSettings='{"dnsServers":["10.0.0.5", "10.0.0.6"]}'
If you are using --set you need to supply the entire object. You may need to escape the double quotes.
...dnsSettings="{\"dnsServers\":[\"10.0.0.5\", \"10.0.0.6\"]}"
If the DNS settings object isn't empty, you could also do this:
az vmss update -n myVmss --add virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].dnsSettings.dnsServers "10.0.0.5"

Related

how to delete relevant resources when deleting a virtual machine

I am using Azure CLI version 2.34.1. I ran following commands to create a resource group and then a virtual machine. Note that I used options to delete relevant resources when the VM is deleted.
az group create --name myTestRG --location eastus
az vm create --resource-group myTestRG --name myTestWindows11VM --image MicrosoftWindowsDesktop:windows-11:win11-21h2-pro:22000.493.220201 --admin-username someusername --os-disk-delete-option delete --nic-delete-option delete
Later I deleted the VM using following command.
az vm delete --name MyTestWin11VM --resource-group myTestRG -y
However, when I browse to the portal, the resource group still showing following resources that are relevant to the VM.
What I may be doing wrong? Is there anyway to delete all resources associated to VM when I delete the virtual machine itself?
UPDATE ITS A BUG:
The way Azure works is to group resources in Resource Groups - its a mandatory field in all creation of services. Azure does this because many resources have dependencies, such as a VM with a NIC, VNet & NSG.
You can use this to your advantage and simply delete the Resource Group:
az group delete --name myTestRG
Azure will work out the dependency order, eg NSG, VNet, NIC, VM. You can read up on how it does the ordering: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/delete-resource-group?tabs=azure-cli
What happens if I have multiple VMs in a Resource Group and I only want to delete one?
There's 3 new options --os-disk-delete-option, --data-disk-delete-option, --nic-delete-option to support deleting VMs and dependencies:
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image UbuntuLTS \
--public-ip-sku Standard \
--nic-delete-option delete \
--os-disk-delete-option delete \
--admin-username azureuser \
--generate-ssh-keys
Otherwise script the whole thing using Azure Resource Manager Templates (ARM Templates), or the new tool to generate ARM Templates called Bicep. It's worth continuing with raw CLI commands and delete dependencies in order. IF you get good with the CLI you end up with a library of commands that you can use with ARM templates.

Cannot get Azure container network profile Id

We are actually deploying container to Azure using Azure CLI and the create command as specify the sample documentation below :
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-vnet
In this dosucmentation it is clearly specify from the sample command below that when the container and the Vnet/Subnet gets created, azure create for you a Network Profile Id ( that is need for yaml deplyoement)
az container create --name appcontainer --resource-group myResourceGroup --image mcr.microsoft.com/azuredocs/aci-helloworld --vnet aci-vnet --vnet-address-prefix 10.0.0.0/16 --subnet aci-subnet --subnet-address-prefix 10.0.0.0/24
After the container gets created successfully you are supposed to get Network profile name or ID, which you can obtain using "az network profile list"
Which in fact does not return anything
UPDATE :
I update m Azure CLI to 2.30 in powershell but the result is the same the output of the command return nohing even if container and vnet gets succesfully created
Output result
Thanks for your help
regards
I have tested in my environment.
I deployed a container to a new virtual network using the below command:
az container create --name appcontainer --resource-group myResourceGroup --image mcr.microsoft.com/azuredocs/aci-helloworld --vnet aci-vnet --vnet-address-prefix 10.0.0.0/16 --subnet aci-subnet --subnet-address-prefix 10.0.0.0/24
The container got successfully created.
To get the Network Profile ID, I used the below command:
az network profile list --resource-group myResourceGroup --query [0].id --output tsv
In this way, we can fetch the Network Profile ID
If network profile is not getting created using CLI, try using ARM template
The same happened to me. I solve it using Azure CLI version 2.27.2. Any newer version leaves me with the same problem.
There seems to be a problem with the latest versions of the Azure CLI

filter log message with "az webapp log tail"

Is it possible to filter out message logs from Azure by the using the Azure CLI, like this
az webapp log tail
I see some posts mention the parameter --filter, however, it looks like that filter has been retired, isn't it?
https://learn.microsoft.com/en-us/cli/azure/webapp/log?view=azure-cli-latest#az_webapp_log_tail
Is there any workaround for that?
Edited: to add a screenshot
Looks like this doc is old, there is no --filter parameter both in az webapp log tail --help or this link az webapp log tail in the latest version.
If you just want to filter with Error, you could use --only-show-errors parameter.
az webapp log tail --name appname --resource-group myResourceGroup --only-show-errors
Or if you want to increase logging verbosity, you could use --verbose.
az webapp log tail --name appname --resource-group myResourceGroup --verbose
Filter specific events, like Error
az webapp log tail --name appname --resource-group myResourceGroup --filter Error

Azure VM change IP address to static via CLI

I am taking a course and stuck for almost a week. I created a VM and now it wants me to change the IP config method to static. The exact words are.
"You have created a ubuntu virtual machine in the second step, in which check the public IP (publicIpAllocationMethod) address and change it to Static by executing the azure CLI commands."
I created the VM with below command.
az vm create -n MyVm1 -g groupname --admin-username "n1234" --admin-password "nk123#9090" --location westUS --image UbuntuLTS
Got the VM NIC with below command.
nic_id=$(az vm show -g gropname -n MyVm1 -d --query networkProfile.networkInterfaces[0].id)
az network nic show --ids MyVm1VMNic
I have the IP of the VM but not sure how to change it to static.
I got it resolved by using the below command.
az network public-ip update -g GROUPNAME -n MyVm1PublicIP --allocation-method Static
What you're looking for can be found here: https://learn.microsoft.com/en-us/cli/azure/network/nic/ip-config?view=azure-cli-latest#az-network-nic-ip-config-update
With your example, you would run the following:
nic_id=$(az vm show -g gropname -n MyVm1 -d --query
networkProfile.networkInterfaces[0].id --output tsv)
nicName=$(az network nic show --ids $nic_id --query name --output tsv)
ipconfig=$(az network nic show --ids $nic_id --query ipConfigurations[0].name
--output tsv)
az network nic ip-config update -g gropname --nic-name $nicName -n $ipconfig --private-ip-address <static ip address>
By setting the private IP, the IP configuration will be updated to static. The above code relies on the VM having a single NIC, which is assumed based on your example.
Hopefully that helps!

How to get private IP of VMSS using CLI

I'm trying to automate few of our BAT script and for this our script need to know the private IP of each instances of VMSS(no public IP for instances).
Is there a way to query the private IP of all instances under a particular VMSS using azure cli. I tried few command of LB and VMSS but didn't find a solution yet.
az vmss show -g <rg> -n <vmss>
az vmss list-instances -g <rg> -n <vmss>
az vmss nic list-vm-nics -g <rg> --vmss-name <vmss> --ids <id>
az network lb address-pool list -g <rg> --lb-name <lb>
az vmss list-instance-connection-info -g <rg> -n <vmss>
Any help is highly appreciable and I'm not looking for powershell.
You can use the Azure CLI and bash command:
az vmss nic list -g groupName --vmss-name ScaleSetName | grep -w "privateIpAddress"
It can show all the private ips like this:
"privateIpAddress": "192.168.1.4",
"privateIpAddress": "192.168.1.5",

Resources