Pass parameters to --custom-data Cloud Init script using az cli - azure

Is there a way to pass parameters to the cloud init script? Trying to achieve something like this:
az vm create ... --custom-data myscript.yml param1 param2
Obviously it is possible to use variables from an ARM template like here: https://github.com/Azure/iotedge-vm-deploy/blob/master/cloud-init.txt#L44

I'm afraid you made the mistake. It's not the parameter for the CLI command az vm create, it's a variable of the Azure Template. You can see the variable docs is defined in the template variables block, and of course, you can then use it in the template for the VM property customData.
Now the CLI command az vm create does not support the parameters for the --custom-data. You can get more details about the cloud-init for Azure VM here.

Related

How to obtain Azure subscription details via Ansible module?

I am getting started with Ansible + Azure. While I see Ansible modules for quite a few tasks, I am kinda stuck at the basic task of obtaining the subscription_id and subscription_name
To work around this I am using the az account show --subscription <subscription_name> command instead. I pull the output of that command into ansible and extract subscription_id and subscription_name
Is there a way to perform this task via an Ansible module instead ?
Looks it is not possible to perform this task via the Ansible module, all the Ansible module on Azure here, there is no one can do this.

Can an ansible VM in Azure query its own VM tags?

I have a VM running in Azure which has ansible installed.
Is it possible to run ansible to find the tags associated with this VM (which ansible is running on)?
Furthermore Can it be done as part of a "lookup" expression?
E.g hosts: {{lookup(tag_name) }}
Elaborating Hassan Raza's suggestion:
This is Azure REST API reference and this is Tags REST API section and this REST API helps to get the entire set of tags on a resource. So you may just use this REST API to accomplish your requirement.
On the other hand, you can also leverage Az PowerShell to get the entire set of tags on a resource and this is that Az PowerShell cmdlet which is part of Az.Resources module so you need it this module imported as a pre-requisite. Again, you may just use this cmdlet from your local machine or from wherever you want to.
On the another hand, you may also create something called Azure Automation Runbook (in general words its a script that's created in Azure cloud under an Azure Automation account). So you may create an Azure Automation account and then a simple runbook to get the entire set of tags on a resource.
The solution we went with was to use the Ansible azure_rm_virtualmachine_info_module :
https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_virtualmachine_info_module.html
This returns azure tag info.

Applying Azure Key Vault no-self-perms property in an ARM template

Trying to deploy an Azure Key Vault but keeping some form of Infrastructure as Code, unfortunately from what I've been able to find the only way you can utilize the --no-self-perms property is with the usage of Azure CLI
https://learn.microsoft.com/en-us/cli/azure/keyvault?view=azure-cli-latest
Is there any simple way that I can still use --no-self-perms property in an ARM template? Even better is there a simple way to use it with terraform (not currently available as a property)
After my validation, you just need to set the accessPolices field like "accessPolicies": [], in your ARM template, then the result will be the same as that you use --no-self-perms property in Azure CLI az keyvault create --location $location --name $MyKeyVault --resource-group $MyResourceGroup --no-self-perms.
If you want to use it with terraform. You could use azurerm_template_deployment to invoke your template with terraform or use local-exec Provisioner under resource "null_resource" to execute Azure CLI commands locally.

Azure - How to list all the Databricks Workspaces in Azure

Could someone please let me know how to list all the DBR workspaces under a particualr subscription in Azure.
I have tried Az Cli Option but it doesn't have any option to list any workspace.
you can always use something like this:
az resource list --resource-type "Microsoft.Databricks/workspaces"
so use a generic command to query the rest api directly (what the other answer suggests) but using Azure CLI, so you dont need to handle the auth\tokens\etc
ps. you'd first need to change your Azure CLI context to that subscription with:
az account set -s "sub_name_goes_here"
You can use the REST API,
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Databricks/workspaces?api-version=2018-04-01

How to use Azure CLI to configure or manage deployment slots in ARM mode

Looks like Azure Powershell has option of slots but ARM mode of Azure CLI is missing these capabilities.
How to setup an ARM template to create a deployment slot?
How to use Azure CLI to deploy an ARM template for a specific slot
Reference:
https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/
Looks like $ azure group deployment create is missing the slot option but it's present in $ azure webapp create <resource-group> <name> --slot <slot-name> -l <location> -p <server-farm-plan-id>.
May be we should create webapp first and then use regular ARM template to update a particular slot by specifying parameter value webSiteName = in following ARM template parameters file.
https://github.com/Azure/azure-quickstart-templates/blob/master/201-web-app-java-tomcat/azuredeploy.parameters.json

Resources