Using Azure CLI Get the 'principalId' value of an Azure Application Gateway - azure-cli

PS /home/ian> az network application-gateway identity show --gateway-name "xxx-inf-abc-wag" --resource-group "network-xxx"
{
"principalId": null,
"tenantId": null,
"type": "userAssigned",
"userAssignedIdentities": {
"/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/network-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/dev-gpp-wag-mi": {
"clientId": "DDDDDDDDD-eb2e-4836-898a-DDDDDDDDD",
"principalId": "UUUUUUUUUU-b7c8-43d2-80a2-UUUUUUUUUU"
}
}
}
I just want to retrieve the value of the field 'principalId' from the above json returned from running 'az network application-gateway identity show'.
I think I need to add "--query ...something". I tried "--query .principalId" but this doesn't work. I know there's something wrong with my syntax for "--query" but don't know how to solve it ?

Solved it by using another az command...
$id = $(az ad sp list --display-name "XXX-abc-wag-mi" --query [0].id --output tsv)

The az network application-gateway identity show works with the following query expression
$id=$(az network application-gateway identity show -g MyResourceGroup --gateway ag1 --query 'userAssignedIdentities."/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1".principalId' -o tsv)
Explanation
The az network application-gateway identity show -g MyResourceGroup --gateway-name ag1 gives the below output:
{
"principalId": null,
"tenantId": null,
"type": "userAssigned",
"userAssignedIdentities": {
"/subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1": {
"clientId": "DDDDDDDDD-eb2e-4836-898a-DDDDDDDDD",
"principalId": "UUUUUUUUUU-b7c8-43d2-80a2-UUUUUUUUUU"
}
}
}
Since the key /subscriptions/XXXXXXXXX-80b8-4447-b2a6-XXXXXXXXXX/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1 contains forward slashes and a dot character (which are special characters), it has to be escaped.
Hence, the key should be quoted with double quotes

Related

Is there a way to use AWS Step Functions Input to assembly command string on System Manager block?

I am creating a Step Function State machine to everytime an instance starts it copy a file from S3 to an specific folder inside this instance. The origin folder inside S3 bucket has a folder named with this instance ID. The instance ID I am passing as input for the System manager block, but I need to use it to create the command string that will be performed inside the EC2.
For example:
My input is: $.detail.instance-id (lets assume the following ID i-11223344556677889)
The Systems Manager API parameters are:
"CloudWatchOutputConfig": {
"CloudWatchLogGroupName": "myloggroup",
"CloudWatchOutputEnabled": true
},
"DocumentName": "AWS-RunShellScript",
"DocumentVersion": "$DEFAULT",
"InstanceIds.$": "States.Array($)",
"MaxConcurrency": "50",
"MaxErrors": "10",
"Parameters": {
"commands": [
{
"runuser -l ec2-user -c \"aws s3 cp s3://my-bucket/**MY_INSTANCEID**/myfile.xyz /home/ec2-user/myfolder/myfile.xyz\""
}
},
"TimeoutSeconds": 6000
}```
Summing up, I want to turn the line with the command replacing the MY_INSTANCEID by my input $.detail.instance-id, and perform the following command:
"runuser -l ec2-user -c "aws s3 cp s3://my-bucket/i-11223344556677889/myfile.xyz /home/ec2-user/myfolder/myfile.xyz""
Is there a way? I already tried to use the Fn::join withou success.
Thank you in advance,
kind regards,
Winner
It was necessary to use State.Format inside the State.Array so the it worked, and State.Format inside the State.Array cannot have quotes:
"CloudWatchOutputConfig": {
"CloudWatchLogGroupName": "myloggroup",
"CloudWatchOutputEnabled": true
},
"DocumentName": "AWS-RunShellScript",
"DocumentVersion": "$DEFAULT",
"InstanceIds.$": "States.Array($)",
"MaxConcurrency": "50",
"MaxErrors": "10",
"Parameters": {
"commands.$": "States.Array(States.Format('runuser -l ec2-user -c \"aws s3 cp s3://my-bucket/**MY_INSTANCEID**/myfile.xyz /home/ec2-user/myfolder/myfile.xyz\"', $))"
},
"TimeoutSeconds": 6000
}```
Was also necessary to use .$ after command.

Powershell access property stored in JSON object

$primaryEndpoints = az storage account show --resource-group rg --name sto --query 'primaryEndpoints'
The above command returns
{
"blob": "https://sto.blob.core.windows.net/",
"dfs": null,
"file": "https://sto.file.core.windows.net/",
"internetEndpoints": null,
"microsoftEndpoints": null,
"queue": "https://sto.queue.core.windows.net/",
"table": "https://sto.table.core.windows.net/",
"web": null
}
But his command below returns nothing :
echo $primaryEndpoints["blob"]
I've also tried
echo $primaryEndpoints.blob
How do I access the json property ?
It seems to me that you are getting a JSON string as a return value. To access the properties by name, you need to first convert the JSON string to a PSObject.
$primaryEndpoints = az storage account show --resource-group rg --name sto --query 'primaryEndpoints'
$primaryEndpointObjects = $primaryEndpoints | ConvertFrom-Json
$primaryEndpointObjects.blob

passing json array with spaces to bash script for az cli tagging

I have a bash script that looks like the following and correctly passes tags to the az cli that includes spaces.
RESOURCE_GROUP_NAME=$1
LOCATION=$2
TAGS_INPUT_ARGUMENT=$3 # This TAGS_INPUT_ARGUMENT needs to finally look like the TAGS below.
echo 'TAGS_INPUT_ARGUMENT:' $TAGS_INPUT_ARGUMENT
# HARD CODED TAGS that Work
TAGS=("owner=Firstname Lastname" "application=cool-name")
echo 'TAGS:' "${TAGS[#]}"
az group create \
--name $RESOURCE_GROUP_NAME \
--location $LOCATION \
--tags "${TAGS[#]}"
I am having problems passing the TAGS into the script.
i.e.
export TAGS='["owner=Firstname Lastname","application=cool-name"]'
bash ./entrypoint.sh rg-lionking eastus2 "${TAGS}"
Output:
TAGS_INPUT_ARGUMENT: ["owner=Firstname Lastname","application=cool-name"]
TAGS: owner=Firstname Lastname application=cool-name
{
"id": "/subscriptions/**REDACTED**/resourceGroups/rg-lionking",
"location": "eastus2",
"managedBy": null,
"name": "rg-lionking",
"properties": {
"provisioningState": "Succeeded"
},
"tags": {
"application": "cool-name",
"owner": "Firstname Lastname"
},
"type": "Microsoft.Resources/resourceGroups"
}
Given that I can get TAGS in a good state, what do I need to do to pass in the same thing in json format and get it working as the final argument to the az group create cli?
My jp knowledge is practically zero, so I am guessing that the answer lies in there somewhere.
The equivalent to expanding an array is on the command line is passing multiple separate arguments
./entrypoint rg-lionking eastus2 "owner=Firstname Lastname" "application=cool-name"
...and then, in entrypoint:
#!/usr/bin/env bash
resource_group_name=$1; shift
location=$1; shift
tags=( "$#" )
az group create \
--name "$resource_group_name" \
--location "$location" \
--tags "${tags[#]}"

Get Node attributes via knife

I have a requirement where I need to get hostname, memory, cores, storage, packages installed for multiple nodes(~1k).
I have approached the solution by using knife.
$ knife search node 'hostname:HostName1 OR hostname:HostName2 OR hostname:HostName3' -a hostname -a cpu.cores -a memory.total -a rpm -a filesystem.by_device -F j|jq '.'
And the typical output of this command is like;
{
"results": 3,
"rows": [
{
"MyHostName1": {
"hostname": "MyHostName1",
"cpu.cores": 4,
"memory.total": "15645184kB",
"rpm": {
"loger-multipath": [
{
"version": "0.4.9",
"release": "123.el7",
"arch": "x86_64"
}
],
"python": [
{
"version": "7.19.0",
"release": "19.el7",
"arch": "x86_64"
}
]
},
"filesystem.by_device": {
"/apps/logger/root_my-root": {
"kb_size": "8125880",
"kb_used": "2426760",
"kb_available": "5263308",
"percent_used": "32%",
"mount_options": [
"rw",
"discard",
"data=ordered"
],
"uuid": "87ujrf56-6yu6-654r-yu43-uy67yg43ws67",
"mounts": [
"/"
]
}
}
}
}
}
However, there are details which I do not need;
How can we set the display sequence same as that of the attribute list in the command, i.e. hostname then core, memory…
We get the file system names and their corresponding sizes, however, we are getting all the other tag values as well; how can we get just the file system name and the ( something similar to what we get from the df command; e.g. apps/logger/root_vg-apps: kb_size: 3997376 )
The output of the rpm attribute gives us the rpm package name, architecture, version and release information, how can we concatenate the output of multiple attributes in a single line ( something similar to the output when we run the yum list installed command; e.g loger-multipath.x86_64 0.4.9-123.el7 )
EDIT:
After much googling this is the progress:
knife search node 'HostName1 OR hostname:HostName2' -a cpu.cores -a memory.total -a filesystem.by_device -F j|jq '.rows[]|keys[] as $hostName|"\($hostName),\(.[$hostName]|."cpu.cores"),\(.[$hostName]|."memory.total"),\(.[$hostName]|."filesystem.by_device")"'
And the corresponding output
"HostName1,4,15645184kB,{\"/dev/mapper/root_vg-root\":{\"kb_size\":\"8125880\",\"kb_used\":\"2425220\",\"kb_available\":\"5264848\",\"percent_used\":\"32%\",\"total_inodes\":\"524288\",\"inodes_used\":\"88441\",\"inodes_available\":\"435847\",\"inodes_percent_used\":\"17%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\",\"discard\",\"data=ordered\"],\"uuid\":\"rthd-762c-41affff8-8927-065fsee20853c681\",\"mounts\":[\"/\"]},\"devtmpfs\":{\"kb_size\":\"7810756\",\"kb_used\":\"0\",\"kb_available\":\"7810756\",\"percent_used\":\"0%\",\"total_inodes\":\"1952689\",\"inodes_used\":\"403\",\"inodes_available\":\"1952286\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"devtmpfs\",\"mount_options\":[\"rw\",\"nosuid\",\"seclabel\",\"size=7810756k\",\"nr_inodes=1952689\",\"mode=755\"],\"mounts\":[\"/dev\"]},\"tmpfs\":{\"kb_size\":\"1564520\",\"kb_used\":\"0\",\"kb_available\":\"1564520\",\"percent_used\":\"0%\",\"total_inodes\":\"1955648\",\"inodes_used\":\"1\",\"inodes_available\":\"1955647\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"tmpfs\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"size=1564520k\",\"mode=700\",\"uid=627000\",\"gid=161\"],\"mounts\":[\"/dev/shm\",\"/run\",\"/sys/fs/cgroup\",\"/run/user/0\",\"/run/user/627000\"]},\"/dev/sda1\":{\"kb_size\":\"499656\",\"kb_used\":\"212068\",\"kb_available\":\"250892\",\"percent_used\":\"46%\",\"total_inodes\":\"32768\",\"inodes_used\":\"350\",\"inodes_available\":\"32418\",\"inodes_percent_used\":\"2%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"data=ordered\"],\"uuid\":\"857fgg-b2a2-42d8-9db2-dfrferf7544\",\"mounts\":[\"/boot\"]},\"/dev/mapper/root_vg-var\":{\"kb_size\":\"5029504\",\"kb_used\":\"4142128\",\"kb_available\":\"608848\",\"percent_used\":\"88%\",\"total_inodes\":\"327680\",\"inodes_used\":\"6191\",\"inodes_available\":\"321489\",\"inodes_percent_used\":\"2%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"noacl\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"dfef155456-ab4c-48f4-a7a5-5454sfdf\",\"mounts\":[\"/var\"]},\"/dev/mapper/root_vg-var--tmp\":{\"kb_size\":\"1998672\",\"kb_used\":\"6180\",\"kb_available\":\"1871252\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"21\",\"inodes_available\":\"131051\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"vfghhhht542-ea7c-4c8b-9afd-frfgvbbn\",\"mounts\":[\"/var/tmp\"]},\"/dev/mapper/root_vg-apps\":{\"kb_size\":\"3997376\",\"kb_used\":\"495044\",\"kb_available\":\"3276236\",\"percent_used\":\"14%\",\"total_inodes\":\"262144\",\"inodes_used\":\"3203\",\"inodes_available\":\"258941\",\"inodes_percent_used\":\"2%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nodev\",\"relatime\",\"seclabel\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"fvfbvfbv55444-a813-4d9c-a9ac-7d50cfbfe345\",\"mounts\":[\"/apps\"]},\"/dev/mapper/root_vg-kdump\":{\"kb_size\":\"1998672\",\"kb_used\":\"6144\",\"kb_available\":\"1871288\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"11\",\"inodes_available\":\"131061\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"frgrghg55-9673-47f5-aaac-4g4g4g1g1\",\"mounts\":[\"/kdump\"]},\"/dev/mapper/root_vg-home\":{\"kb_size\":\"1998672\",\"kb_used\":\"6544\",\"kb_available\":\"1870888\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"83\",\"inodes_available\":\"130989\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"frbj4874-fe4d-4f82-ad86-41554ffv\",\"mounts\":[\"/home\"]},\"/dev/mapper/root_vg-tmp\":{\"kb_size\":\"1998672\",\"kb_used\":\"7916\",\"kb_available\":\"1869516\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"51\",\"inodes_available\":\"131021\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"a995fd05-90a8-46a8-a192-0a02f68e476a\",\"mounts\":[\"/tmp\"]},\"/dev/mapper/root_vg-gcis2\":{\"kb_size\":\"20511312\",\"kb_used\":\"3191304\",\"kb_available\":\"16255048\",\"percent_used\":\"17%\",\"total_inodes\":\"1310720\",\"inodes_used\":\"33967\",\"inodes_available\":\"1276753\",\"inodes_percent_used\":\"3%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"fb4bb78a-7f33-47f1-87a6-dcbe50bc6349\",\"mounts\":[\"/apps/gcis2\"]},\"sysfs\":{\"fs_type\":\"sysfs\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\",\"seclabel\"],\"mounts\":[\"/sys\"]},\"proc\":{\"fs_type\":\"proc\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\"],\"mounts\":[\"/proc\"]},\"securityfs\":{\"fs_type\":\"securityfs\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\"],\"mounts\":[\"/sys/kernel/security\"]},\"devpts\":{\"fs_type\":\"devpts\",\"mount_options\":[\"rw\",\"nosuid\",\"noexec\",\"relatime\",\"seclabel\",\"gid=5\",\"mode=620\",\"ptmxmode=000\"],\"mounts\":[\"/dev/pts\"]},\"cgroup\":{\"fs_type\":\"cgroup\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\",\"seclabel\",\"net_prio\",\"net_cls\"],\"mounts\":[\"/sys/fs/cgroup/systemd\",\"/sys/fs/cgroup/perf_event\",\"/sys/fs/cgroup/blkio\",\"/sys/fs/cgroup/freezer\",\"/sys/fs/cgroup/cpu,cpuacct\",\"/sys/fs/cgroup/memory\",\"/sys/fs/cgroup/pids\",\"/sys/fs/cgroup/hugetlb\",\"/sys/fs/cgroup/cpuset\",\"/sys/fs/cgroup/devices\",\"/sys/fs/cgroup/net_cls,net_prio\"]},\"pstore\":{\"fs_type\":\"pstore\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\"],\"mounts\":[\"/sys/fs/pstore\"]},\"configfs\":{\"fs_type\":\"configfs\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/kernel/config\"]},\"selinuxfs\":{\"fs_type\":\"selinuxfs\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/fs/selinux\"]},\"systemd-1\":{\"fs_type\":\"autofs\",\"mount_options\":[\"rw\",\"relatime\",\"fd=30\",\"pgrp=1\",\"timeout=0\",\"minproto=5\",\"maxproto=5\",\"direct\",\"pipe_ino=16127\"],\"mounts\":[\"/proc/sys/fs/binfmt_misc\"]},\"debugfs\":{\"fs_type\":\"debugfs\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/kernel/debug\"]},\"hugetlbfs\":{\"fs_type\":\"hugetlbfs\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\"],\"mounts\":[\"/dev/hugepages\"]},\"mqueue\":{\"fs_type\":\"mqueue\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\"],\"mounts\":[\"/dev/mqueue\"]},\"binfmt_misc\":{\"fs_type\":\"binfmt_misc\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/proc/sys/fs/binfmt_misc\"]},\"fusectl\":{\"fs_type\":\"fusectl\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/fs/fuse/connections\"]},\"/dev/fd0\":{},\"/dev/sda\":{},\"/dev/sda2\":{\"fs_type\":\"LVM2_member\",\"uuid\":\"zrtcBv-4y6D-LG2a-Wt6M-h18d-K0BQ-zyl11h\"},\"/dev/mapper/root_vg-swap\":{\"fs_type\":\"swap\",\"uuid\":\"vfbvejgbg5456454-93a1-4a67-b33f-gtrbbbn\"},\"/dev/mapper/root_vg-pool0_tmeta\":{},\"/dev/mapper/root_vg-pool0-tpool\":{},\"/dev/mapper/root_vg-pool0\":{},\"/dev/mapper/root_vg-pool0_tdata\":{},\"rootfs\":{\"fs_type\":\"rootfs\",\"mount_options\":[\"rw\"],\"mounts\":[\"/\"]}}"
"HostName2,4,15645184kB,{\"/dev/mapper/root_vg-root\":{\"kb_size\":\"8125880\",\"kb_used\":\"2425220\",\"kb_available\":\"5264848\",\"percent_used\":\"32%\",\"total_inodes\":\"524288\",\"inodes_used\":\"88441\",\"inodes_available\":\"435847\",\"inodes_percent_used\":\"17%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\",\"discard\",\"data=ordered\"],\"uuid\":\"rthd-762c-41affff8-8927-065fsee20853c681\",\"mounts\":[\"/\"]},\"devtmpfs\":{\"kb_size\":\"7810756\",\"kb_used\":\"0\",\"kb_available\":\"7810756\",\"percent_used\":\"0%\",\"total_inodes\":\"1952689\",\"inodes_used\":\"403\",\"inodes_available\":\"1952286\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"devtmpfs\",\"mount_options\":[\"rw\",\"nosuid\",\"seclabel\",\"size=7810756k\",\"nr_inodes=1952689\",\"mode=755\"],\"mounts\":[\"/dev\"]},\"tmpfs\":{\"kb_size\":\"1564520\",\"kb_used\":\"0\",\"kb_available\":\"1564520\",\"percent_used\":\"0%\",\"total_inodes\":\"1955648\",\"inodes_used\":\"1\",\"inodes_available\":\"1955647\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"tmpfs\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"size=1564520k\",\"mode=700\",\"uid=627000\",\"gid=161\"],\"mounts\":[\"/dev/shm\",\"/run\",\"/sys/fs/cgroup\",\"/run/user/0\",\"/run/user/627000\"]},\"/dev/sda1\":{\"kb_size\":\"499656\",\"kb_used\":\"212068\",\"kb_available\":\"250892\",\"percent_used\":\"46%\",\"total_inodes\":\"32768\",\"inodes_used\":\"350\",\"inodes_available\":\"32418\",\"inodes_percent_used\":\"2%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"data=ordered\"],\"uuid\":\"857fgg-b2a2-42d8-9db2-dfrferf7544\",\"mounts\":[\"/boot\"]},\"/dev/mapper/root_vg-var\":{\"kb_size\":\"5029504\",\"kb_used\":\"4142128\",\"kb_available\":\"608848\",\"percent_used\":\"88%\",\"total_inodes\":\"327680\",\"inodes_used\":\"6191\",\"inodes_available\":\"321489\",\"inodes_percent_used\":\"2%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"noacl\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"dfef155456-ab4c-48f4-a7a5-5454sfdf\",\"mounts\":[\"/var\"]},\"/dev/mapper/root_vg-var--tmp\":{\"kb_size\":\"1998672\",\"kb_used\":\"6180\",\"kb_available\":\"1871252\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"21\",\"inodes_available\":\"131051\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"vfghhhht542-ea7c-4c8b-9afd-frfgvbbn\",\"mounts\":[\"/var/tmp\"]},\"/dev/mapper/root_vg-apps\":{\"kb_size\":\"3997376\",\"kb_used\":\"495044\",\"kb_available\":\"3276236\",\"percent_used\":\"14%\",\"total_inodes\":\"262144\",\"inodes_used\":\"3203\",\"inodes_available\":\"258941\",\"inodes_percent_used\":\"2%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nodev\",\"relatime\",\"seclabel\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"fvfbvfbv55444-a813-4d9c-a9ac-7d50cfbfe345\",\"mounts\":[\"/apps\"]},\"/dev/mapper/root_vg-kdump\":{\"kb_size\":\"1998672\",\"kb_used\":\"6144\",\"kb_available\":\"1871288\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"11\",\"inodes_available\":\"131061\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"frgrghg55-9673-47f5-aaac-4g4g4g1g1\",\"mounts\":[\"/kdump\"]},\"/dev/mapper/root_vg-home\":{\"kb_size\":\"1998672\",\"kb_used\":\"6544\",\"kb_available\":\"1870888\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"83\",\"inodes_available\":\"130989\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"frbj4874-fe4d-4f82-ad86-41554ffv\",\"mounts\":[\"/home\"]},\"/dev/mapper/root_vg-tmp\":{\"kb_size\":\"1998672\",\"kb_used\":\"7916\",\"kb_available\":\"1869516\",\"percent_used\":\"1%\",\"total_inodes\":\"131072\",\"inodes_used\":\"51\",\"inodes_available\":\"131021\",\"inodes_percent_used\":\"1%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"relatime\",\"seclabel\",\"discard\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"a995fd05-90a8-46a8-a192-0a02f68e476a\",\"mounts\":[\"/tmp\"]},\"/dev/mapper/root_vg-gcis2\":{\"kb_size\":\"20511312\",\"kb_used\":\"3191304\",\"kb_available\":\"16255048\",\"percent_used\":\"17%\",\"total_inodes\":\"1310720\",\"inodes_used\":\"33967\",\"inodes_available\":\"1276753\",\"inodes_percent_used\":\"3%\",\"fs_type\":\"ext4\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\",\"stripe=16\",\"data=ordered\"],\"uuid\":\"fb4bb78a-7f33-47f1-87a6-dcbe50bc6349\",\"mounts\":[\"/apps/gcis2\"]},\"sysfs\":{\"fs_type\":\"sysfs\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\",\"seclabel\"],\"mounts\":[\"/sys\"]},\"proc\":{\"fs_type\":\"proc\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\"],\"mounts\":[\"/proc\"]},\"securityfs\":{\"fs_type\":\"securityfs\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\"],\"mounts\":[\"/sys/kernel/security\"]},\"devpts\":{\"fs_type\":\"devpts\",\"mount_options\":[\"rw\",\"nosuid\",\"noexec\",\"relatime\",\"seclabel\",\"gid=5\",\"mode=620\",\"ptmxmode=000\"],\"mounts\":[\"/dev/pts\"]},\"cgroup\":{\"fs_type\":\"cgroup\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\",\"seclabel\",\"net_prio\",\"net_cls\"],\"mounts\":[\"/sys/fs/cgroup/systemd\",\"/sys/fs/cgroup/perf_event\",\"/sys/fs/cgroup/blkio\",\"/sys/fs/cgroup/freezer\",\"/sys/fs/cgroup/cpu,cpuacct\",\"/sys/fs/cgroup/memory\",\"/sys/fs/cgroup/pids\",\"/sys/fs/cgroup/hugetlb\",\"/sys/fs/cgroup/cpuset\",\"/sys/fs/cgroup/devices\",\"/sys/fs/cgroup/net_cls,net_prio\"]},\"pstore\":{\"fs_type\":\"pstore\",\"mount_options\":[\"rw\",\"nosuid\",\"nodev\",\"noexec\",\"relatime\"],\"mounts\":[\"/sys/fs/pstore\"]},\"configfs\":{\"fs_type\":\"configfs\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/kernel/config\"]},\"selinuxfs\":{\"fs_type\":\"selinuxfs\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/fs/selinux\"]},\"systemd-1\":{\"fs_type\":\"autofs\",\"mount_options\":[\"rw\",\"relatime\",\"fd=30\",\"pgrp=1\",\"timeout=0\",\"minproto=5\",\"maxproto=5\",\"direct\",\"pipe_ino=16127\"],\"mounts\":[\"/proc/sys/fs/binfmt_misc\"]},\"debugfs\":{\"fs_type\":\"debugfs\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/kernel/debug\"]},\"hugetlbfs\":{\"fs_type\":\"hugetlbfs\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\"],\"mounts\":[\"/dev/hugepages\"]},\"mqueue\":{\"fs_type\":\"mqueue\",\"mount_options\":[\"rw\",\"relatime\",\"seclabel\"],\"mounts\":[\"/dev/mqueue\"]},\"binfmt_misc\":{\"fs_type\":\"binfmt_misc\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/proc/sys/fs/binfmt_misc\"]},\"fusectl\":{\"fs_type\":\"fusectl\",\"mount_options\":[\"rw\",\"relatime\"],\"mounts\":[\"/sys/fs/fuse/connections\"]},\"/dev/fd0\":{},\"/dev/sda\":{},\"/dev/sda2\":{\"fs_type\":\"LVM2_member\",\"uuid\":\"zrtcBv-4y6D-LG2a-Wt6M-h18d-K0BQ-zyl11h\"},\"/dev/mapper/root_vg-swap\":{\"fs_type\":\"swap\",\"uuid\":\"vfbvejgbg5456454-93a1-4a67-b33f-gtrbbbn\"},\"/dev/mapper/root_vg-pool0_tmeta\":{},\"/dev/mapper/root_vg-pool0-tpool\":{},\"/dev/mapper/root_vg-pool0\":{},\"/dev/mapper/root_vg-pool0_tdata\":{},\"rootfs\":{\"fs_type\":\"rootfs\",\"mount_options\":[\"rw\"],\"mounts\":[\"/\"]}}"
I know this seems a bit messy; any help is welcome
looking at the json provided in the question, it seems that your query does not use the right values for the key that you specify -- namely, hostname -- you specified hostname:HostName1 where it feels it needs to be hostname:MyHostName1.
also, you can drop the node argument from the search command and specify it in the query, such as node:my.node.name.

Filter on nested array with jmespath (using az cli)

I would like to know if a value in a TXT record is already available in the DNS:
az network dns record-set txt show -g myresourcegroup -z 'mydomain' -n 'mytxtvalues'
This is the part of the json result where it's all about:
"txtRecords": [
{
"value": [
"abc"
]
},
{
"value": [
"def"
]
}
]
I tried many queries. These are 2 which I expected to work.
az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query txtRecords[?value[?starts_with(#, 'abc')]]
az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query txtRecords[*].value[?starts_with(#, 'abc')]]
The result is:
At line:1 char:123
+ ... 'mytxtvalues' --query txtRecords[?value[?starts_with(#, 'abc') ...
+ ~ Unrecognized token in source text. At line:1 char:124
+ ... 'mytxtvalues' --query txtRecords[?value[?starts_with(#, 'abc')] ...
+ ~ Missing argument in parameter list.
It looks like the # used to filter the array is not recognized. But I don't know how to query otherwise.
What would be a correct query to know if value abc is already in the list?
You need to use the command like this:
az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query "txtRecords[*].value[?starts_with(#, 'abc')]"
And if you just need to output the string you can append the parameter -o tsv. Hope this will help you.