azure-samples / azure-cli-samples Goto Github PK
View Code? Open in Web Editor NEWContains Azure CLI scripts samples used for documentation at https://docs.microsoft.com
License: MIT License
Contains Azure CLI scripts samples used for documentation at https://docs.microsoft.com
License: MIT License
Some scripts contains logic which is hard to write in sh or bat and most probably users will also be using .py for writing such scripts.
Can we add .py scripts into this repo?
Side Query:
Once a sample .sh is added then where it can be discovered?
Hi,
thanks for theses samples here, very helpful.
I found a minor problem in this script with service endpoint for CosmosDB:
https://github.com/Azure-Samples/azure-cli-samples/blob/master/cosmosdb/common/service-endpoints.sh
The line with 'Variable block' is missing a leading '#'. It should read
#Variable block
Using this script, I can list all the account keys for a Cosmos DB database:
az cosmosdb list-keys
--name $accountName
--resource-group $resourceGroupName
Page "https://github.com/Azure-Samples/azure-cli-samples/blob/master/app-service/configure-ssl-certificate/configure-ssl-certificate-webapp-only.sh" is linked directly from "https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate?tabs=apex#how-can-i-automate-adding-a-bring-your-owncertificate-to-an-app" in the instructions sections for "Azure CLI: Bind a custom TLS/SSL certificate to a web app"
configure-ssl-certificate-webapp-only.sh does not provision the webapp as described, and seems to link to a page (app-service/scripts/cli-configure-ssl-certificate.md) which also doesn't appear to exist.
az vm extension set
--publisher Microsoft.Compute
--version 1.8
--name CustomScriptExtension
--vm-name myVM
--resource-group myResourceGroup
--settings '{"commandToExecute":"powershell.exe Install-WindowsFeature -Name Web-Server"}'
Returns:
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
Looking for a solution where I can get Keys and Values with its labels from feature management of app configuration. I do not want to use given Spring libraries. Can anyone please get me to the right direction.
Please include examples that show how to use the update
method. There is a particular request for updating NSG rulesets from a JSON file as a single batch.
See Azure/azure-cli-samples#3 for the initial request.
FYI it seems valid to point out that user should either use a small string in --credential-description or make use of the suggested az rest call until we wait for az ad sp credential reset to accept bigger pwds or limit the amount of chars in that param with a friendlier error.
FYI here is the az rest suggestion:
https://github.com/Azure-Samples/azure-cli-samples/tree/master/azure-front-door/deploy-custom-domain
Work with @dbradish-microsoft and @carlrab to update these samples, including:
Opening the issue here although this may be an Azure CLI bug.
We have a snapshot "SS-1" that resides in Resource Group "RG-1" which lives in Subscription "A-1". The idea was to use the Azure CLI to copy that snapshot into Storage Account "SA-1", inside Container "C-1", as VHD "SS-1.vhd" under the Subscription "A-2". I used the example script here as a template, and received the errors mentioned below.
After trying a few things with the CLI, I decided to try the same operation with the Powershell Azure Module. For that I followed this script here, and that worked as expected.
I was under the impression these operations were similar and should work the same. Am I missing something, or is this a bug with the CLI?
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=26db9db0-3a8b-11eb-bd33-d0abd52dec12 Retry policy did not allow for a retry: Server-Timestamp=Thu, 10 Dec 2020 01:58:10 GMT, Server-Request-ID=0603f00d-201e-0048-4197-ce479b000000, HTTP status code=403, Exception=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. ErrorCode: CannotVerifyCopySource<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.RequestId:0603f00d-201e-0048-4197-ce479b000000Time:2020-12-10T01:58:11.1978438Z</Message></Error>.
azure.cli.core.util.handle_exception is called with an exception:
Traceback (most recent call last):
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-2huwp6jm\knack\cli.py", line 215, in invoke
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 654, in execute
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 717, in _run_jobs_serially
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 709, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-_skkczbr\azure\cli\command_modules\storage\__init__.py", line 342, in new_handler
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 688, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 325, in __call__
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\__init__.py", line 784, in default_command_handler
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\blob\blockblobservice.py", line 1018, in copy_blob
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\blob\baseblobservice.py", line 3261, in _copy_blob
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\storageclient.py", line 430, in _perform_request
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\storageclient.py", line 358, in _perform_request
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\storageclient.py", line 344, in _perform_request
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\_error.py", line 115, in _http_error_handler
azure.common.AzureHttpError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. ErrorCode: CannotVerifyCopySource
<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:0603f00d-201e-0048-4197-ce479b000000
Time:2020-12-10T01:58:11.1978438Z</Message></Error>
Command arguments: ['storage', 'blob', 'copy', 'start', '--debug', '--destination-blob', '<redacted>', '--destination-container', '<redacted>', '--account-name', '<redacted>', '--account-key', '<redacted>', '--source-uri', 'https://<redacted>.blob.core.windows.net/<redacted>/<redacted>?sv=2018-03-28']
Event: Cli.PreExecute []
Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x02B1CA08>, <function OutputProducer.on_global_arguments at 0x02CAAE88>, <function CLIQuery.on_global_arguments at 0x02CCFE88>]
Event: CommandInvoker.OnPreCommandTableCreate []
Modules found from index for 'storage': ['azure.cli.command_modules.storage']
Loading command modules:
Name Load Time Groups Commands
storage 0.091 52 238
Total (1) 0.091 52 238
Loaded 52 groups, 238 commands.
Found a match in the command table.
Raw command : storage blob copy start
Command table: storage blob copy start
Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x02F37E88>]
az_command_data_logger : command args: storage blob copy start --debug --destination-blob {} --destination-container {} --account-name {} --account-key {} --source-uri {}
Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x02F8FA50>, <function register_global_query_examples_argument.<locals>.register_query_examples at 0x02F991E0>]
Event: CommandInvoker.OnPostArgumentLoad []
Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x02F99228>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x02F992B8>]
Event: CommandInvoker.OnCommandTableLoaded []
Event: CommandInvoker.OnPreParseArgs []
Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x02CAAED0>, <function CLIQuery.handle_query_parameter at 0x02CCFED0>, <function register_global_query_examples_argument.<locals>.handle_example_parameter at 0x02F8FBB8>,
<function register_ids_argument.<locals>.parse_ids_arguments at 0x02F99270>]
Getting data service client service_type=BlockBlobService
azure.multiapi.storage.v2018_11_09.common._auth : String_to_sign=PUT
x-ms-client-request-id:<redacted>
x-ms-copy-source:https://<redacted>.blob.core.windows.net/<redacted>/<redacted>?sv=2018-03-28
x-ms-date:Thu, 10 Dec 2020 01:58:09 GMT
x-ms-version:2018-11-09
/<redacted>/<redacted>/<redacted>
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=<redacted> Outgoing request: Method=PUT, Path=/images/our_test.vhd, Query={'timeout': None}, Headers={'x-ms-copy-source': 'https://<redacted>.blob.core.windows.net/<redacted>/<redacted>?sv=2018-03-28', 'x-ms-source-if-modified-since': None, 'x-ms-source-if-unmodified-since': None, 'x-ms-source-if-match': None, 'x-ms-source-if-none-match': None, 'If-Modified-Since': None, 'If-Unmodified-Since': None, 'If-Match': None, 'If-None-Match': None, 'x-ms-lease-id': None, 'x-ms-source-lease-id': None, 'x-ms-access-tier': None, 'x-ms-requires-sync': None, 'x-ms-version': '2018-11-09', 'User-Agent': 'Azure-Storage/2.0.0-2.0.1 (Python CPython 3.6.8; Windows 10) AZURECLI/2.16.0 (MSI)', 'x-ms-client-request-id': '<redacted>', 'x-ms-date': 'Thu, 10 Dec 2020 01:58:09 GMT', 'Authorization': 'REDACTED'}.
urllib3.connectionpool : Starting new HTTPS connection (1): <redacted>.blob.core.windows.net:443
urllib3.connectionpool : https://<redacted>.blob.core.windows.net:443 "PUT /<redacted>/<redacted> HTTP/1.1" 403 322
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=<redacted> Receiving Response: Server-Timestamp=Thu, 10 Dec 2020 01:58:10 GMT, Server-Request-ID=0603f00d-201e-0048-4197-ce479b000000, HTTP Status Code=403, Message=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature., Headers={'content-length': '322', 'content-type': 'application/xml', 'server': 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id': '0603f00d-201e-0048-4197-ce479b000000', 'x-ms-version': '2018-11-09', 'x-ms-error-code': 'CannotVerifyCopySource', 'date': 'Thu, 10 Dec 2020 01:58:10 GMT'}.
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=<redacted> Operation failed: checking if the operation should be retried. Current retry count=0, Server-Timestamp=Thu, 10 Dec 2020 01:58:10 GMT, Server-Request-ID=0603f00d-201e-0048-4197-ce479b000000, HTTP status code=403, Exception=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. ErrorCode: CannotVerifyCopySource<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.RequestId:0603f00d-201e-0048-4197-ce479b000000Time:2020-12-10T01:58:11.1978438Z</Message></Error>.
$sourceSubscriptionId = '<redacted>'
$sourceResourceGroupName = '<redacted>'
$snapshotName = '<redacted>'
$sasExpiryDuration = "3600"
$targetStorageAccountName = "<redacted>"
$targetStorageContainerName = "<redacted>"
$targetStorageAccountKey = "<redacted>"
$targetVHDFileName = "<redacted>"
Select-AzSubscription -SubscriptionId $sourceSubscriptionId
$sas = Grant-AzSnapshotAccess -ResourceGroupName $sourceResourceGroupName -SnapshotName $snapshotName -DurationInSecond $sasExpiryDuration -Access Read
$destinationContext = New-AzStorageContext -StorageAccountName $targetStorageAccountName -StorageAccountKey $targetStorageAccountKey
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $targetStorageContainerName -DestContext $destinationContext -DestBlob $targetVHDFileName
$sourceSubscriptionId = '<redacted>'
$sourceResourceGroupName = '<redacted>'
$snapshotName = '<redacted>'
$sasExpiryDuration = '3600'
$targetStorageAccountName = "<redacted>"
$targetStorageContainerName = "<redacted>"
$targetStorageAccountKey = "<redacted>"
$targetVHDFileName = "<redacted>"
az account set --subscription $sourceSubscriptionId
$sas = az snapshot grant-access --resource-group $sourceResourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --access-level "Read" --query [accessSas] -o tsv
az storage blob copy start --debug --destination-blob $targetVHDFileName --destination-container $targetStorageContainerName --account-name $targetStorageAccountName --account-key $targetStorageAccountKey --source-uri $sas
Hi,
Would you add an example of adding custom-data as an inline text argument instead of file reference?
Not sure if this is correct.
az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --generate-ssh-keys --custom-data '#cloud-config\nhostname: myhostname'
Refering to
https://github.com/Azure-Samples/azure-cli-samples/tree/master/virtual-machine/create-vm-customdata
Thanks!
A few months ago, there was an example located at:
Has that resource been permanently removed or is it located elsewhere?
Can it be restored?
Thanks in advance
I tried to to create a VN scale set as indicated in create-vmss.sh but with a load balancer and not application gateway. I created Vnet, Subnet, public IP addr, loadbalancer with the public IP, http rule then the VMSS. When I try to access the IP , I get
The connection has timed out
The server at 20.199.112.60 is taking too long to respond.
Here are the steps I followed
1 - az network vnet create \
--name vnet-myrg \
--resource-group myrg \
--address-prefix 10.0.0.0/16 \
--subnet-name subnet-myrg \
--subnet-prefixes 10.0.0.0/24
2 - az network vnet subnet create \
--name Subnet-vnet-myrg \
--resource-group myrg \
--vnet-name vnet-myrg \
--address-prefix 10.0.2.0/24
3 - az network public-ip create \
--resource-group myrg \
--name myrgPubIPAddr \
--sku Standard
4 - az network lb create \
--resource-group myrg \
--name myrgLB \
--sku Standard \
--public-ip-address myrgPubIPAddr \
--frontend-ip-name myFrontEnd \
--backend-pool-name myBackEndPool
5 - az network lb probe create \
--resource-group myrg \
--lb-name myrgLB \
--name myHealthProbe \
--protocol tcp \
--port 80
6 - az network lb rule create \
--resource-group myrg \
--lb-name myrgLB \
--name myHTTPRule \
--protocol tcp \
--frontend-port 80 \
--backend-port 80 \
--frontend-ip-name myFrontEnd \
--backend-pool-name myBackEndPool \
--probe-name myHealthProbe \
--disable-outbound-snat true \
--idle-timeout 15 \
--enable-tcp-reset true
7 - az vmss create \
--name myrg \
--resource-group myrg \
--image Ubuntu2204 \
--admin-username azureuser \
--admin-password Azure123456! \
--instance-count 2 \
--vnet-name vnet-myrg \
--subnet Subnet-vnet-myrg \
--vm-sku Standard_DS1_v2 \
--upgrade-policy-mode Automatic \
--lb myrgLB \
--backend-pool-name myBackEndPool \
--custom-data cloud-init.txt
What might be wrong in this config? Is there a sample here for using load balancer instead of application gateway?
At https://github.com/xinity/azure-cli, there is a command as follows
az vm show -g [tab][tab]
what is [tab][tab]? when I run it in terminal I get
az: error: unrecognized arguments: [tab][tab]
https://github.com/Azure-Samples/azure-cli-samples/tree/master/azure-front-door/deploy-custom-domain
As discussed, let's try building a GitHub action that will periodically test and assert:
These test assets will also be useful to users of this sample.
https://github.com/Azure-Samples/azure-cli-samples/tree/master/redis-cache
The scripts in this folder needed to checked and rerun.
echo "Creating $resourceGroup in "$location"..."
az group create --name $resourceGroup --location "$location" --tags $tag
echo "Creating $cache"
az redis create --name $cache --resource-group $resourceGroup --location "$location" --sku $sku --vm-size $size
echo "Showing details of $cache"
az redis show --name $cache --resource-group $resourceGroup
redis=($(az redis show --name $cache --resource-group $resourceGroup --query [hostName,enableNonSslPort,port,sslPort] --output tsv))
keys=($(az redis list-keys --name $cache --resource-group $resourceGroup --query [primaryKey,secondaryKey] --output tsv))
echo "Hostname:" ${redis[0]}
echo "Non SSL Port:" ${redis[2]}
echo "Non SSL Port Enabled:" ${redis[1]}
echo "SSL Port:" ${redis[3]}
echo "Primary Key:" ${keys[0]}
echo "Secondary Key:" ${keys[1]}
echo "Deleting $cache"
az redis delete --name $resourceGroup --resource-group $resourceGroup -y
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.