You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/extensions/custom-script-linux.md
+45-55Lines changed: 45 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,9 @@ ms.date: 03/29/2023
14
14
15
15
The Custom Script Extension Version 2 downloads and runs scripts on Azure virtual machines (VMs). Use this extension for post-deployment configuration, software installation, or any other configuration or management task. You can download scripts from Azure Storage or another accessible internet location, or you can provide them to the extension runtime.
16
16
17
-
The Custom Script Extension integrates with Azure Resource Manager templates. You can also run it by using the Azure CLI, PowerShell, or the Azure Virtual Machines REST API.
17
+
The Custom Script Extension integrates with Azure Resource Manager templates. You can also run it by using the Azure CLI, Azure PowerShell, or the Azure Virtual Machines REST API.
18
18
19
-
This article details how to use the Custom Script Extension from the Azure CLI, and how to run the extension by using an Azure Resource Manager template. This article also provides troubleshooting steps for Linux systems.
19
+
This article describes how to use the Custom Script Extension from the Azure CLI, and how to run the extension by using an Azure Resource Manager template. This article also provides troubleshooting steps for Linux systems.
20
20
21
21
There are two versions of the Custom Script Extension:
22
22
@@ -37,14 +37,14 @@ You can set the extension to use your Azure Blob Storage credentials so that it
37
37
38
38
### Internet connectivity
39
39
40
-
If you need to download a script externally, such as from GitHub or Azure Storage, then you need to open other firewall or network security group (NSG) ports. For example, if your script is located in Azure Storage, you can allow access by using Azure NSG [service tags for Storage](../../virtual-network/network-security-groups-overview.md#service-tags).
40
+
To download a script externally, such as from GitHub or Azure Storage, you need to open other firewall or network security group (NSG) ports. For example, if your script is located in Azure Storage, you can allow access by using Azure NSG [service tags for Storage](../../virtual-network/network-security-groups-overview.md#service-tags).
41
41
42
42
If your script is on a local server, you might still need to open other firewall or NSG ports.
43
43
44
44
### Tips and tricks
45
45
46
-
- The highest failure rate for this extension is due to syntax errors in the script. Test that the script runs without errors. Put more logging into the script to make it easier to find failures.
47
-
- Write scripts that are idempotent, so running them more than once accidentally doesn't cause system changes.
46
+
- The highest failure rate for this extension is due to syntax errors in the script. Verify that the script runs without errors. Put more logging into the script to make it easier to find failures.
47
+
- Write scripts that are idempotent, so that running them more than once accidentally doesn't cause system changes.
48
48
- Ensure that the scripts don't require user input when they run.
49
49
- The script is allowed 90 minutes to run. Anything longer results in a failed provision of the extension.
50
50
- Don't put reboots inside the script. Restarting causes problems with other extensions that are being installed, and the extension doesn't continue after the reboot.
@@ -54,14 +54,14 @@ If your script is on a local server, you might still need to open other firewall
54
54
- You can have only one version of an extension applied to the VM. To run a second custom script, update the existing extension with a new configuration. Alternatively, you can remove the Custom Script Extension and reapply it with the updated script.
55
55
- If you want to schedule when a script runs, use the extension to create a cron job.
56
56
- When the script is running, you only see a *transitioning* extension status from the Azure portal or CLI. If you want more frequent status updates for a running script, create your own solution.
57
-
- The Custom Script Extension doesn't natively support proxy servers. However, you can use a file transfer toolthat supports proxy servers within your script, such as `Curl`.
57
+
- The Custom Script Extension doesn't natively support proxy servers. However, you can use a file transfer tool, such as `Curl`, that supports proxy servers within your script.
58
58
- Be aware of nondefault directory locations that your scripts or commands might rely on. Have logic to handle this situation.
59
59
60
60
## Extension schema
61
61
62
62
The Custom Script Extension configuration specifies things like script location and the command to be run. You can store this information in configuration files, specify it on the command line, or specify it in an Azure Resource Manager template.
63
63
64
-
You can store sensitive data in a protected configuration, which is encrypted and only decrypted on the target virtual machine. The protected configuration is useful when the execution command includes secrets such as a password. Here's an example:
64
+
You can store sensitive data in a protected configuration, which is encrypted and only decrypted on the target VM. The protected configuration is useful when the execution command includes secrets such as a password. Here's an example:
65
65
66
66
```json
67
67
{
@@ -123,26 +123,26 @@ You can store sensitive data in a protected configuration, which is encrypted an
123
123
|`apiVersion`| Not applicable | You can find the most up-to-date API version by using [Resource Explorer](https://resources.azure.com/) or by using the command `az provider list -o json` in the Azure CLI. |
124
124
|`fileUris`| Optional | URLs for files to be downloaded. |
125
125
|`commandToExecute`| Required if `script` isn't set | The entry point script to run. Use this property instead of `script` if your command contains secrets such as passwords. |
126
-
|`script`| Required if `commandToExecute` isn't set | A Base64-encoded (and optionally gzip'ed) script run by `/bin/sh`. |
126
+
|`script`| Required if `commandToExecute` isn't set | A Base64-encoded and optionally gzip'ed script run by `/bin/sh`. |
127
127
|`skipDos2Unix`| Optional | Set this value to `false` if you want to skip dos2unix conversion of script-based file URLs or scripts. |
128
128
|`timestamp`| Optional | Change this value only to trigger a rerun of the script. Any integer value is acceptable, as long as it's different from the previous value. |
129
129
|`storageAccountName`| Optional | The name of storage account. If you specify storage credentials, all `fileUris` values must be URLs for Azure blobs. |
130
130
|`storageAccountKey`| Optional | The access key of the storage account. |
131
-
|`managedIdentity`| Optional | The [managed identity](../../active-directory/managed-identities-azure-resources/overview.md) for downloading files: `clientId` (optional, string): The client ID of the managed identity. `objectId` (optional, string): The object ID of the managed identity.|
131
+
|`managedIdentity`| Optional | The [managed identity](../../active-directory/managed-identities-azure-resources/overview.md) for downloading files. Values are `clientId` (optional, string), which is the client ID of the managed identity, and `objectId` (optional, string), which is the object ID of the managed identity.|
132
+
133
+
*Public settings* are sent in clear text to the VM where the script runs. *Protected settings* are encrypted through a key known only to Azure and the VM. The settings are saved to the VM as they were sent. That is, if the settings were encrypted, they're saved encrypted on the VM. The certificate that's used to decrypt the encrypted values is stored on the VM. The certificate is also used to decrypt settings, if necessary, at runtime.
134
+
135
+
Using public settings might be useful for debugging, but we strongly recommend that you use protected settings.
132
136
133
137
You can set the following values in either public or protected settings. The extension rejects any configuration where these values are set in both public and protected settings.
134
138
135
139
-`commandToExecute`
136
140
-`script`
137
141
-`fileUris`
138
142
139
-
Using public settings might be useful for debugging, but we strongly recommend that you use protected settings.
140
-
141
-
Public settings are sent in clear text to the VM where the script runs. Protected settings are encrypted through a key known only to Azure and the VM. The settings are saved to the VM as they were sent. That is, if the settings were encrypted, they're saved encrypted on the VM. The certificate that's used to decrypt the encrypted values is stored on the VM. The certificate is also used to decrypt settings, if necessary, at runtime.
142
-
143
143
#### Property: skipDos2Unix
144
144
145
-
The previous version of the Custom Script Extension, `Microsoft.OSTCExtensions.CustomScriptForLinux`, would automatically convert DOS files to UNIX files by translating `\r\n` to `\n`. This translation still exists and is on by default. This conversion is applied to all files downloaded from `fileUris` or the script setting based on either of the following criteria:
145
+
The previous version of the Custom Script Extension, `Microsoft.OSTCExtensions.CustomScriptForLinux`, automatically converts DOS files to UNIX files by translating `\r\n` to `\n`. This translation still exists and is on by default. This conversion is applied to all files downloaded from `fileUris` or the script setting based on either of the following criteria:
146
146
147
147
- The extension is *.sh*, *.txt*, *.py*, or *.pl*. The script setting always matches this criterion because it's assumed to be a script run with */bin/sh*. The script setting is saved as *script.sh* on the VM.
The Custom Script Extension uses the following algorithm to run a script:
201
201
202
-
1. Assert that the length of the script's value doesn't exceed 256 KB.
203
-
1. Base64 decode the script's value.
204
-
1._Try_ to gunzip the Base64-decoded value.
205
-
1. Write the decoded and optionally decompressed value to disk (*/var/lib/waagent/custom-script/#/script.sh*).
206
-
1. Run the script by using `_/bin/sh -c /var/lib/waagent/custom-script/#/script.sh`.
202
+
1. Assert that the length of the script's value doesn't exceed 256 KB.
203
+
1. Base64 decode the script's value.
204
+
1._Try_ to gunzip the Base64-decoded value.
205
+
1. Write the decoded and optionally decompressed value to disk: */var/lib/waagent/custom-script/#/script.sh*.
206
+
1. Run the script by using `_/bin/sh -c /var/lib/waagent/custom-script/#/script.sh`.
207
207
208
208
#### Property: managedIdentity
209
209
210
210
> [!NOTE]
211
211
> This property *must* be specified in protected settings only.
212
212
213
-
The Custom Script Extension version 2.1 and later supports [managed identities](../../active-directory/managed-identities-azure-resources/overview.md) for downloading files from URLs provided in the `fileUris` setting. This approach allows the Custom Script Extension to access Azure Storage private blobs or containers without the user having to pass secrets like shared access signature (SAS) tokens or storage account keys.
213
+
The Custom Script Extension, version 2.1 and later, supports [managed identities](../../active-directory/managed-identities-azure-resources/overview.md) for downloading files from URLs provided in the `fileUris` setting. This approach allows the Custom Script Extension to access Azure Storage private blobs or containers without the user having to pass secrets like shared access signature (SAS) tokens or storage account keys.
214
214
215
215
To use this feature, add a [system-assigned](../../app-service/overview-managed-identity.md?tabs=dotnet#add-a-system-assigned-identity) or [user-assigned](../../app-service/overview-managed-identity.md?tabs=dotnet#add-a-user-assigned-identity) identity to the VM or Virtual Machine Scale Set where the Custom Script Extension is expected to run. Then [grant the managed identity access to the Azure Storage container or blob](../../active-directory/managed-identities-azure-resources/tutorial-vm-windows-access-storage.md#grant-access).
216
216
@@ -282,7 +282,7 @@ You can deploy Azure VM extensions by using Azure Resource Manager templates. Th
282
282
283
283
## Azure CLI
284
284
285
-
When you're using the Azure CLI to run the Custom Script Extension, create a configuration file or files. At a minimum, you must have`commandToExecute`.
285
+
When you use the Azure CLI to run the Custom Script Extension, create a configuration file or files. At a minimum, the configuration file must contain`commandToExecute`. The `az vm extension set` command refers to the configuration file:
286
286
287
287
```azurecli
288
288
az vm extension set \
@@ -292,7 +292,7 @@ az vm extension set \
292
292
--protected-settings ./script-config.json
293
293
```
294
294
295
-
Optionally, you can specify the settings in the command as a JSON-formatted string. This approach allows the configuration to be specified during execution and without a separate configuration file.
295
+
Alternatively, you can specify the settings in the command as a JSON-formatted string. This approach allows the configuration to be specified during execution and without a separate configuration file.
296
296
297
297
```azurecli
298
298
az vm extension set \
@@ -316,53 +316,43 @@ This example uses the following script file named *script-config.json*:
316
316
317
317
1. Create the script file by using the text editor of your choice or by using the following CLI command:
0 commit comments