Rehan Ch
Rehan Ch

Reputation: 853

download files in azure vm using fileuri

"fileUris": [
                "https://files.blob.core.windows.net/extensions/test.sh"]

In an Azure scale set, does this part of extension download the file test.sh to the VM or call it directly from blob storage?

Upvotes: 1

Views: 3699

Answers (1)

kim
kim

Reputation: 3421

I'm assuming you are talking about the custom script extension for Azure virtual machines.

On its documentation page it reads:

The Custom Script Extension downloads and executes scripts on Azure virtual machines. This extension is useful for post deployment configuration, software installation, or any other configuration / management task. Scripts can be downloaded from Azure storage or GitHub, or provided to the Azure portal at extension run time. The Custom Script extension integrates with Azure Resource Manager templates, and can also be run using the Azure CLI, PowerShell, Azure portal, or the Azure Virtual Machine REST API.

Highlighted are the relevant parts.

The extension work so that it first downloads and then executes the scripts you provide for it.

Edit: If you need to deploy some external resources you can upload them to your GitHub account or an Azure Storage Blob and download/read them from there.

See for example this answer for more details on how to download a file from a blob.

Invoke-WebRequest -Uri https://jasondisk2.blob.core.windows.net/msi/01.PNG -outfile 'C:\'

If you simply want to read the json file, then you can do as described here in this other answer.

$response = Invoke-RestMethod -Uri "https://yadayada:8080/bla"
$response.flag 

Note: Invoke-RestMethod automatically converts the json response to a psobject.

As for the working directory. The extension downloads its files into the following directory

C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.*\Downloads\<n>

where <n> is a decimal integer which may change between executions of the extension. The 1.* value matches the actual, current typeHandlerVersion value of the extension.

For example, the actual directory could be

C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.8\Downloads\2

See the troubleshooting section in the Azure documentation for more information.

Alternatively, for a Linux based system the path is similar to

/var/lib/waagent/custom-script/download/0/

see this page for more information.

Upvotes: 2

Related Questions