无法通过命令行界面使用标签筛选 Azure 资源。

huangapple go评论50阅读模式
英文:

Unable to filter Azure resource using tags through cli

问题

我有多个具有标签 site:prod 的命名空间资源

az tag list --resource-id "subscriptions/[subsc_id]/resourceGroups/[rg_id]/providers/Microsoft.ServiceBus/namespaces/[ns_name]"
{
  "id": "/subscriptions/[subsc_id]/resourceGroups/[rg_id]/providers/Microsoft.ServiceBus/namespaces/[ns_name]/providers/Microsoft.Resources/tags/default",
  "name": "default",
  "properties": {
    "tags": {
      "module": "payment",
      "site": "prod"
    }
  },
  "resourceGroup": "[rg_id]",
  "type": "Microsoft.Resources/tags"
}

我想要检索所有具有上述 site:prod 标签的资源,使用以下 cli 命令运行:

az servicebus namespace list --subscription "[subsc_id]" --query '[?tags.site=="prod"]'

然而,运行上述命令产生完全相反的输出,没有一个返回的命名空间对象带有标签 site:prod

我在这里做错了什么?

英文:

I have multiple namespace resources with tag site:prod

az tag list --resource-id "subscriptions/[subsc_id]/resourceGroups/[rg_id]/providers/Microsoft.ServiceBus/namespaces/[ns_name]"         
{
  "id": "/subscriptions/[subsc_id]/resourceGroups/[rg_id]/providers/Microsoft.ServiceBus/namespaces/[ns_name]/providers/Microsoft.Resources/tags/default",
  "name": "default",
  "properties": {
    "tags": {
      "module": "payment",
      "site": "prod"
    }
  },
  "resourceGroup": "[rg_id]",
  "type": "Microsoft.Resources/tags"
}

I want retrieve all resource such as above which have site:prod tag using cli command, by running following:

az servicebus namespace list --subscription "[subsc_id]" --query '[?tags.site=="prod"]'

However, running above command produces completely opposite output such that none of the returned namespace objects have tag site:prod on them.

What am I doing wrong here?

答案1

得分: 0

我在你的代码中找到了问题:你在使用 "(引号)时出现了错误:

az servicebus namespace list --subscription "Subscription name" --query "[?tags.site=='prod']"

无法通过命令行界面使用标签筛选 Azure 资源。

你应该将 " 放在查询的开头,将 ' 放在查询中间。

或者,

无法通过命令行界面使用标签筛选 Azure 资源

你可以简单地使用以下命令获取所有具有标签 site=prod 的资源名称:

$s= az resource list --tag site=prod 
$res=$s | ConvertFrom-json          
$res.name     

无法通过命令行界面使用标签筛选 Azure 资源。

英文:

I found the problem in your code: you are using " (quotation) incorrectly:

az servicebus namespace list --subscription "Subscription name" --query "[?tags.site=='prod']"

无法通过命令行界面使用标签筛选 Azure 资源。

You should keep " at the starting of query and ' in middle of query

Alternatively,

>Unable to filter Azure resource using tags through cli

You can simply use below command to get all the resources names which have tags site=prod:

$s= az resource list --tag site=prod 
$res=$s | ConvertFrom-json          
$res.name     

无法通过命令行界面使用标签筛选 Azure 资源。

huangapple
  • 本文由 发表于 2023年2月16日 07:34:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定